Next.js Discord

Discord Forum

How do I get response object, print it and use it from Google after authenticating?

Unanswered
Brown bear posted this in #help-forum
Open in Discord
Avatar
Brown bearOP
import { useSession, signIn, signOut } from "next-auth/react";
const session =useSession();
const onClick = async () => {
    console.log('hello Iamhere')
     signIn("google");
    const response = session.response;
    console.log(`my response is ${response}`);
  };

 <button onClick={onClick}>Sign in</button>


I am able to sign in with google but not able to use its response object. All of these console logs are not printing anything.

This is how I am handling auth if that will come handy :

import NextAuth from "next-auth"
import GoogleProvider from "next-auth/providers/google";

const handler = NextAuth({
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID?? '',
clientSecret: process.env.GOOGLE_CLIENT_SECRET?? ''
}),
],

})

export {handler as GET, handler as POST};

Please help me get the JSON object I get back from google. How will I see the tokens that google sends? I need to send a token to validate user at server side.

0 Replies