-
SummaryI have a NestJS backend that has its own authentication in jwt and NextJs + next-auth application and I want to implement login by Google functionality but next auth is using its own generated token I want next-auth to use my own access tokens from the NestJS backend, how can I do that? I tried to put the callback URL to the backend to send the authenticated user to the backend and redirect the request to the next auth callback with the user from the database with the custom-generated token next-auth Provider
in Nest
but after the user login with his Google account, I got an error from the backend missing code verifier Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
Hi! Any update? |
Beta Was this translation helpful? Give feedback.
-
Any updates? |
Beta Was this translation helpful? Give feedback.
-
I have made an API route in the backend that takes Google token and verifies it and if the token is valid it returns the logged-in user from the database and in the sign-in callback in the next auth I set the user from the backend async signIn({ user, account }) {
if (account?.provider === "google") {
const dbUser = await fetch(
`${process.env.BACKEND_URL}/auth/google/token?token=${account?.id_token}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
},
).then((r) => r.json());
if (!dbUser?.data?.user) return false;
user.id = dbUser?.data?.user?.id;
user.email = dbUser?.data?.user?.email;
user.firstName = dbUser?.data?.user?.firstName;
user.lastName = dbUser?.data?.user?.lastName;
user.avatar = dbUser?.data?.user?.avatar;
user.isEmailVerified = dbUser?.data?.user?.isEmailVerified;
user.isPhoneVerified = dbUser?.data?.user?.isPhoneVerified;
user.token = dbUser?.data?.accessToken;
return true;
}
return true;
}, |
Beta Was this translation helpful? Give feedback.
-
i guess this is the solution but this is a little bit bad for someone who wants flexibility, like i have prisma in my nest js project with a great schema , account , user, tokens ,blacklisting etc next auth is nice when you want to have a solution only in nextjs , like it is limited , but if backend is somewhere else , like an api , it is a disaster i guess. |
Beta Was this translation helpful? Give feedback.
I have made an API route in the backend that takes Google token and verifies it and if the token is valid it returns the logged-in user from the database and in the sign-in callback in the next auth I set the user from the backend