meorocy14422
@meorocy14422
Reviews Written
-
Average Rating
-
Posts
Q&A
connect.sid ์ญ์ ๊ฐ ๋์ง ์์ต๋๋ค.
๋ฉฐ์น ํผ์ ์๋ํด๋ณด๋ค๊ฐ ์๋ผ์ ๊ฒฐ๊ตญ ๋ต๋ณ์ผ๋ก ์ง๋ฌธ ๋ค์ ๋จ๊น๋๋ค ใ ์ ์ฆ์์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.๋ก๊ทธ์ธ ์ดํ ํน์ ํ์ด์ง ์ด๋ ์ connect.sid๊ฐ s%3...์ผ๋ก ๋ณ๊ฒฝ๋จ๋ก๊ทธ์์์์๋ ์ญ์ ๋์ง ์๊ณ ์์ ๋์ผํ๊ฒ ๋ณ๊ฒฝ๋จ. (์๋ ์ฌ์ง)(์ฌ์ง)์์๋ณ๋ก ์ฃผ์์ผ๋ก ์ค๋ช ๋๋ฆฌ๊ฒ ์ต๋๋ค.๋ก๊ทธ์ธ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.// ํ๋ก ํธ์์ ์๋์ ๊ฐ์ด ๋ก๊ทธ์ธ์ ์๋ํฉ๋๋ค async function onSubmit(data: z.infer) { const result = await signIn("credentials", { email: data.email, password: data.password, redirect: false, }); if (result?.error) { alert("์์ด๋ / ๋น๋ฐ๋ฒํธ๋ฅผ ๋ค์ ํ์ธํด์ฃผ์ธ์."); } else { router.replace("/"); } } // ๋ฐฑ์๋์์๋ ์ปจํธ๋กค๋ฌ๋ฅผ ๊ฑฐ์ณ ์๋์ ๊ฐ์ด ํ ํฐ์ ๋ฐ๊ธํฉ๋๋ค. async setRefreshTokenToUser(user: IUser, response) { const payload = { .... }; const { accessToken, refreshToken } = await this.generateTokens(payload); await this.authRepository.setRefreshToken(user.id, refreshToken); response.cookie('connect.sid', accessToken, { httpOnly: true, sameSite: 'none', secure: false, path: '/', domain: 'localhost', }); } // ์ดํ ํ๋ก ํธ์ auth.ts์์๋ ๋ค์๊ณผ ๊ฐ์ด ๋ก๊ทธ์ธ ๋ก์ง์ ์งํ์ค์ ๋๋ค. authorize: async (credentials): Promise => { const res = await login( credentials.email as string, credentials.password as string ); if (res.ok && res.status === 204) { let setCookie = res.headers.get("set-cookie"); if (setCookie) { const parsed = cookie.parse(setCookie); const token = parsed["connect.sid"]; cookies().set("connect.sid", token); const user = jwtDecode(parsed["connect.sid"]); return { ...user, }; } } if (res.status === 401) { const result = await res.json(); throw new Error(result.message || "Failed to login"); } return null; }, }), ], //loginํจ์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. export const login = async (email: string, password: string) => { const res = await fetch(`${BASE_URL}/login/email`, { method: "POST", headers: { "Content-Type": "application/json", }, credentials: "include", body: JSON.stringify({ email, password }), }); return res; }; ๋ก๊ทธ์์์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.// ๋ก๊ทธ์์ ๋ฒํผ์์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. const onLogout = async () => { await signOut({ callbackUrl: "/" }); // router.replace("/"); }; // ํ๋ก ํธ์ auth.ts์ ๋๋ค. nextauth ๋ก๊ทธ์์์ ๋จผ์ ์งํํ๊ณ connect.sid๋ฅผ ์ญ์ ํ๋ ค๊ณ ํ์์ต๋๋ค. events: { signOut: async (data) => { const token = cookies().get("connect.sid"); if (!token) return; await logout(token.value); }, }, // ๋ก๊ทธ์์ fetch ์ ๋๋ค (๋ฌ๋ฌ๋ถ๋ถ์ ์๋ํฐ ์ค๋ฅ๋ก ๋์ฒด) export const logout = async (token: string) => { const res = await fetch(`${BASE_URL}/logout`, { method: "POST", headers: { Authorization : `Bearer (๋ฌ๋ฌ){token}` } credentials: "include", return res; }; // ์๋ฒ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. logout(request: any, response: Response) { const { user } = request; response.clearCookie('connect.sid', { httpOnly: true, sameSite: 'none', secure: false, path: '/', domain: 'localhost', }); return this.authRepository.invalidateRefreshToken(user.id); } ๊ฐ๋ฅํ ํผ์ ํด๊ฒฐํด๋ณด๋ คํ๋๋ฐ ์์๋๋ค์.. ์ด๋ ๋ถ๋ถ์ ์์ ํด์ผํ ๊น์ ใ
- 0
- 3
- 366
Q&A
connect.sid ์ญ์ ๊ฐ ๋์ง ์์ต๋๋ค.
๋ค path์ domain๋ ๋์ผํฉ๋๋ค. ๋ธ๋ผ์ฐ์ ๋ก ์๋ตํ๋ ๋ถ๋ถ์ด ์์ด์์. ๋ธ๋ผ์ฐ์ ๊ฐ ์๋ต์ ๋ฐ์์ผ ์ฟ ํค๊ฐ ์ง์์ง๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ฟ ํค๊ฐ ์ง์์ง ๋ ๋คํธ์ํฌ ํญ์์ Set-Cookie๊ฐ ์์ด์ผ ํฉ๋๋ค.์ ๋์ํ์ง ์๋์ง ์ด ๋ถ๋ถ ์กฐ๊ธ ๋ ์์ธํ ์ค๋ช ํด์ฃผ์ค์ ์์ผ์ค๊น์ ! returnํด์ฃผ๊ณ ๋คํธ์ํฌํญ์ ํ์ธํด๋ณด๋๋ฐ ์ด๋ค ์์ ์ด ํ์ํ์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค ใ
- 0
- 3
- 366
Q&A
์๋ ํ์ธ์. nginx๊ด๋ จ ์ค๋ฅ์ธ๊ฒ ๊ฐ์ต๋๋ค.
ํ ๋น ๋ฅธ ๋ต๋ณ ๊ฐ์ฌํฉ๋๋ค !์ฐ์ ํด๊ฒฐ ํ์์ต๋๋ค.๋ง์ํด์ฃผ์ pm2๋ก ์คํํ์๊ธฐ์ ํด๋น path๋ก ๊ฐ์ weberror์ wervererror๋ฅผ ํ์ธํ์์ต๋๋ค.๋ฌธ์ ๋ ์๋ฒ๋ mongoose์๋ฌ์ cors์๋ฌํด๋ผ์ด์ธํธ๋ path not defined๋ฌธ์ ์์ต๋๋ค..envํ์ผ์ git ignoreํ์ด์ ๋๋น์ ์ฐ๊ฒฐ๋ ์ฝ๋๊ฐ ์์์ต๋๋ค.cors์ค์ ๋ ๋ง์ฐฌ๊ฐ์ง๋ก routes53์ ํตํด ๋ฐ์ ๋๋ฉ์ธ์ ๋ฑ๋กํ์ง์์์์ต๋๋ค.server ์คํ ์ฝ๋์ path๋ฅผ requireํ์ง ์์์ต๋๋ค.์ฌ์ํ ์ค์๋ก ๋น๋กฏ๋ ๋ฌธ์ ์์ง๋ง ํด๊ฒฐํ์ง ๋ชปํ์๋๋ฐ์๋ ค์ฃผ์ ์๋ฌ๋ก๊ทธ ๋ณด๋๋ฒ์ผ๋ก ํ์ธํ๋๋ฒ์ ์์์ต๋๋ค.๊ฐ์ฌํฉ๋๋ค.์ถ๊ฐ ์ง๋ฌธ์ด ์๋ค๋ฉด ์ ๊ฐ ์๋ฌ ๋ฐ์์ ์ฌ๋ฌ๋ฒ ์ ์์ ํ์ด์ ์๋ฌ๋ก๊ทธ๊ฐ ์์ฑ์ด ๊ฝค ๋์ด์๋๋ฐ ๋ก๊ทธ๊ฐ ์์๋ณด๊ธฐ ์ฝ๊ฒ? ์์ฑ๋๊ฒ ํ๋๋ฒ?๊ฐ์๊ฒ์ด ์์๊น์ ?
- 0
- 2
- 755




