Next.js Discord

Discord Forum

Google Login integration

Answered
Anay-208 posted this in #help-forum
Open in Discord
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();
  }
View full answer

18 Replies

Bump
bump x2
bump x3
@Anay-208 Source: https://developers.google.com/identity/sign-in/web/sign-in
if you click the link of Deprecation and Sunset guide, you should see what to use
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
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
Bump
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
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