When Google redirects the user back to our app, we will get a bunch of data on the redirect URL, for example:
http://localhost:3000/login?code=4%2F1QGpS37E21TcgQhhIvJZlK1cG4M1jpPJ0I_XPQgrFjvKUFUJQ3aYuO1zYsqPmKgNb4Wfd8ito88yDjUTD6CKD3E&scope=email%20profile%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%20openid&authuser=1&prompt=consent
It is quite difficult to read and decipher when you first look at it, but it is just a query string with parameters appended to our redirect URL:
<redirect URL>?
code=4/1QFvWYDSrW...
&scope=email profile...
&authuser=1
&prompt=consent
We can use a Node.js module, query-string, to parse the query string in the URL, for example:
const queryString = require('query-string')
const parsed = queryString.parse(location.search)
console.log(parsed)
Then you will get the following JavaScript object...