DEV Community

Cover image for Implementing Sign In with Google in NodeJS (without third-party libraries)

Implementing Sign In with Google in NodeJS (without third-party libraries)

Akshat Mittal on February 20, 2024

Introduction Recently I was building a project in NextJS in which I needed to implement 'Sign in with Google' without third-party librar...
Collapse
 
faisaln profile image
Faisal • Edited

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):

  1. code: req.body.code, the code supplied is not in req.body, instead it is given through req.query. It is also important to note that after successful login it redirects to the GET URL, not POST.

  2. oauthResponseData = oauthResponse.data, but oauthResponse does not have a child data. Instead, just use oauthResponse. You can then use id_token from oauthResponse later.

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!