Google Login integration
Answered
Anay-208 posted this in #help-forum
Anay-208OP
What should I do about integrating google login because js api is depreciated
Answered by Anay-208
using this worked for me:
function handleSignIn() {
const client = window.google.accounts.oauth2.initCodeClient({
client_id: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
scope:
"https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
ux_mode: "popup",
callback: (response) => {
// Do something
},
});
client.requestCode();
}18 Replies
Anay-208OP
Bump
Anay-208OP
bump x2
Anay-208OP
bump x3
Anay-208OP
Need help in what should I use. I basically need a google login system for logging into a ecomm site
last time, I just set redirect uri to a api route, and after verifying email, it just generates a token to give to the user
next-auth
Anay-208OP
I’m not planning on using next auth. I just need oAuth logins and want to implement it from scratch
@Ray if you click the link of `Deprecation and Sunset` guide, you should see what to use
its there. Google Identity Service for Web
@Anay-208 Need help in what should I use. I basically need a google login system for logging into a ecomm site
Anay-208OP
There are 2 options for token system there
Anay-208OP
a screenshot for your convenience in: https://developers.google.com/identity/oauth2/web/guides/migration-to-gis
Anay-208OP
Bump
Anay-208OP
bump
This is pretty simple and lightweight library to implement all kinds of OAuth
the above may be better, but i got it working with simple code if you just need to get the id google provides and match it against your db:
* https://github.com/RiskyMH/Forms/blob/main/app/(auth)/api/oauth/google/route.ts#L25-L53
* https://github.com/RiskyMH/Forms/blob/main/app/(auth)/login/page.tsx#L20
* https://github.com/RiskyMH/Forms/blob/main/app/(auth)/api/oauth/google/route.ts#L25-L53
* https://github.com/RiskyMH/Forms/blob/main/app/(auth)/login/page.tsx#L20
Anay-208OP
using this worked for me:
function handleSignIn() {
const client = window.google.accounts.oauth2.initCodeClient({
client_id: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
scope:
"https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
ux_mode: "popup",
callback: (response) => {
// Do something
},
});
client.requestCode();
}Answer