Replies: 5 comments
-
It looks like you're redirecting from the |
Beta Was this translation helpful? Give feedback.
-
@davidpc-pg, thanks for reply. const authOptions = {
secret: process.env.NEXTAUTH_SECRET,
session: {
strategy: "jwt",
},
providers: [
GoogleProvider({
clientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
clientSecret: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_SECRET,
}),
],
callbacks: {
async signIn({ user, account, profile }) {
if (account?.provider === "google") {
if (!profile) {
throw new ReferenceError();
}
const existingUser = await userService.findUser({
email: profile.email,
});
user.isNewUser = existingUser === null;
if (existingUser) {
user.id = existingUser.id;
user.name = existingUser.name;
user.email = existingUser.email;
user.picture = existingUser.picture;
return "/main";
} else {
user.name = profile.name;
user.email = profile.email;
user.email_verified = profile.email_verified;
user.picture = profile.picture;
return "/join";
}
}
return false;
},
async jwt({ token, account, user }) {
if (account) {
token.isNewUser = user.isNewUser;
token.id = user.id;
token.name = user.name;
token.email = user.email;
token.email_verified = user.email_verified;
token.picture = user.picture;
}
return token;
},
async session({ session, token, user }) {
if (token) {
session.user.isNewUser = token.isNewUser;
session.user.id = token.id;
session.user.name = token.name as string | undefined;
session.user.email = token.email as string | undefined;
session.user.picture = token.picture as string | undefined;
session.user.email_verified = token.email_verified;
}
return session;
},
},
} |
Beta Was this translation helpful? Give feedback.
-
It appears you're still redirecting from |
Beta Was this translation helpful? Give feedback.
-
@davidpc-pg, thank for reply. |
Beta Was this translation helpful? Give feedback.
-
Right. The second note in the section you linked to explains that redirecting (which is what you're doing if you return a string) cancels the authentication flow. |
Beta Was this translation helpful? Give feedback.
-
This is a typical flow of web services.
"/join page", I would like to deliver the nickname, agreement on terms and conditions, and Google Profile to the server together.
But, I can't read Google Profile.
api/auth/[...nextauth]/route.ts
join/page.tsx
Beta Was this translation helpful? Give feedback.
All reactions