Introduction
Recently I was building a project in NextJS in which I needed to implement 'Sign in with Google' without third-party librar...
For further actions, you may consider blocking this person and/or reporting abuse
Hello Akshat,
Thank you for your post. I believe there is a need to adjust the environment variable for the google client secret as shown below:
From
NEXT_PUBLIC_GOOGLE_OAUTH_CLIENT_SECRET="your oauth client secret"To
GOOGLE_OAUTH_CLIENT_SECRET="your oauth client secret"The "NEXT_PUBLIC_" should only be used when you intend to expose your environment variable to the user's client or browser.
Checkout the nextjs official docs for more information on this topic
Hey, amazing article! It's helping me with integrating Google Sign-in with my webapp. I had to convert some of the code to Vanilla JavaScript, but that was pretty easy!
I did find a couple of errors in your code (errors at least for me):
code: req.body.code, the code supplied is not inreq.body, instead it is given throughreq.query. It is also important to note that after successful login it redirects to theGETURL, notPOST.oauthResponseData = oauthResponse.data, butoauthResponsedoes not have a childdata. Instead, just useoauthResponse. You can then useid_tokenfromoauthResponselater.Despite these, I found the article very straightforward. It was very easy to use the method to create a login link and get user details, and also sticks with the idea of being dependent-free. Thanks for this one!