Skip to content

Commit

Permalink
Fix: redirect url 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
soulchicken committed Oct 2, 2023
1 parent 5eec383 commit 83eca73
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const authOptions: NextAuthOptions = {
password: credentials?.password || '',
provider: 'credential',
});

if (data.nickname && data.accessToken) {
const user = {
accessToken: data.accessToken,
Expand All @@ -56,7 +57,6 @@ export const authOptions: NextAuthOptions = {
email: credentials?.email,
id: data.memberId,
};

return user;
}
return null;
Expand All @@ -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',
Expand Down Expand Up @@ -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;
},
},
};

Expand Down

0 comments on commit 83eca73

Please sign in to comment.