Skip to content

Next Auth google OAuth with custom backend access token #8884

Answered by msobkyy
msobkyy asked this question in Help
Discussion options

You must be logged in to vote

I have made an API route in the backend that takes Google token and verifies it and if the token is valid it returns the logged-in user from the database and in the sign-in callback in the next auth I set the user from the backend

    async signIn({ user, account }) {
      if (account?.provider === "google") {
        const dbUser = await fetch(
          `${process.env.BACKEND_URL}/auth/google/token?token=${account?.id_token}`,
          {
            method: "GET",
            headers: {
              "Content-Type": "application/json",
            },
          },
        ).then((r) => r.json());

        if (!dbUser?.data?.user) return false;

        user.id = dbUser?.data?.user?.id;

Replies: 4 comments 8 replies

Comment options

You must be logged in to vote
1 reply
@msobkyy
Comment options

Comment options

You must be logged in to vote
3 replies
@msobkyy
Comment options

@emimaricic
Comment options

@emimaricic
Comment options

Comment options

You must be logged in to vote
3 replies
@poby123
Comment options

@trongtai37
Comment options

@VelHRH
Comment options

Answer selected by msobkyy
Comment options

You must be logged in to vote
1 reply
@caturbgs
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
8 participants