Next.js Discord

Discord Forum

Google authentication

Unanswered
Savannah posted this in #help-forum
Open in Discord
SavannahOP
Hi, I've just finished my connection system with Google using NextAuth, but I have a question about registering with Google. Does it work the same way? How do I save the email in the database?

21 Replies

Komondor
There should be a callback you can hook into when a google user signs in
The example is here, they even use Google in the example
https://next-auth.js.org/providers/google
@Komondor There should be a callback you can hook into when a google user signs in
SavannahOP
Good evening, yes, a colleague told me about it. I finally succeeded, thank you very much for your help 😉
Would you mind if I send you my code and you tell me if my way of doing things is right/logical?
@Komondor send it over!
SavannahOP
Thanks, here you are !
(sorry i don't have nitro ^^)
@Savannah Thanks, here you are !
Komondor
That's the correct approach. However, I would not call your API to create the user. Since you're already on the server it's a wasted trip out to the internet to come back in to your own server
In the signin callback, you should check that the provider is google, like in the sample docs
Komondor
Given that you're using the jwt strategy, I don't know if you will be provided account and profile in the signin callback when using credentials provider
Thank you very much for your help, so I've changed my code by removing the call to my api for account creation 😉
SavannahOP
Hey @Komondor. Did you know how i can redirect users into another page in a client component ? Because, when the user already exists, i want to redirect him into the dashboard. But actually i can't do that because this is a client component :
Komondor
In a client component you would use the useRouter hook
@Komondor In a client component you would use the useRouter hook
SavannahOP
Okay, thanks a lot ! And lastly, do you know how I could pass props to a page using router.push (or something else that allows me to redirect to a page)? I've looked at various sources, including the official nextjs doc, but I can't find anything that works at the moment ^^
Komondor
Passing props to a page can only be done with url query params
@Komondor Passing props to a page can only be done with url query params
SavannahOP
Did you have any example please ?