How to setup Google OAuth2 Login

Basically, I call

const res = await Parse.Cloud.run("GoogleSignIn");

This will return the link to authenticate the user with Google. Then, I redirect to that link using

window.location.href = oauthLink;

When the user login, Google will redirect to the link that I specified in my Google Settings (e.g. http://localhost:3000/redirect)

Then, on page Redirect I run this code when the page loads

const authData = await Parse.Cloud.run("GoogleToken", params);
const user = new Parse.User();
const res = await user.linkWith("google", { authData });

In my Database Browser, I saw that the user is created and that the id, id_token, and access_token are inside authData

However, I don’t have the correct username and the email is not there neither. So, I need to adapt that