From 83eca73561c77950d8861bd5e7196d36fbc9f4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=8C=EC=9A=B8=EC=B9=98=ED=82=A8?= <90738604+soulchicken@users.noreply.github.com> Date: Mon, 2 Oct 2023 20:30:58 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20redirect=20url=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/api/auth/[...nextauth].ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/pages/api/auth/[...nextauth].ts b/src/pages/api/auth/[...nextauth].ts index 19ae611..a33f229 100644 --- a/src/pages/api/auth/[...nextauth].ts +++ b/src/pages/api/auth/[...nextauth].ts @@ -47,6 +47,7 @@ export const authOptions: NextAuthOptions = { password: credentials?.password || '', provider: 'credential', }); + if (data.nickname && data.accessToken) { const user = { accessToken: data.accessToken, @@ -56,7 +57,6 @@ export const authOptions: NextAuthOptions = { email: credentials?.email, id: data.memberId, }; - return user; } return null; @@ -75,7 +75,7 @@ export const authOptions: NextAuthOptions = { callbacks: { async signIn({ user, account }) { if (account?.type === 'credentials') return true; - const response = await fetch(`${process.env.NEXT_PUBLIC_CLIENT_SERVER_URL || 'http://localhost:3000/api'}/users/social-login`, { + const response = await fetch(`${process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:3000/api'}/members/login`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -111,11 +111,14 @@ export const authOptions: NextAuthOptions = { return session; }, - // async redirect({ url, baseUrl }) { - // return url.startsWith(baseUrl) - // ? Promise.resolve(url) - // : Promise.resolve(baseUrl); - // }, + async redirect({ url, baseUrl }) { + if (url.startsWith('/')) { + return `${baseUrl}${url}`; + } if (new URL(url).origin === baseUrl) { + return `${baseUrl}`; + } + return baseUrl; + }, }, };