Next Auth google OAuth with custom backend access token

541 views Asked by At

I have a NestJS backend that has its own authentication in jwt and NextJs + next-auth application and I want to implement login by Google functionality but next auth is using its own generated token I want next-auth to use my own access tokens from the NestJS backend, how can I do that?

I tried to put the callback URL to the backend to send the authenticated user to the backend and redirect the request to the next auth callback with the user from the database with the custom-generated token

next-auth Provider

GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
      authorization: {
        params: {
          request_uri: `${process.env.BACKEND_URL}/auth/google/callback`,
        },
      },
    }),

in Nest

@Public()
    @Get('google/callback')
    @UseGuards(GoogleOAuthGuard)
    @Redirect('f')
    googleAuthRedirect(@Request() req) {
        console.log('success');
        return null;
        // return this.appService.googleLogin(req);
    }

but after the user login with his Google account, I got an error from the backend

missing code verifier

How can I tell next-auth to store the user from the nest backend database that is authenticated by Google, not the user is returned by Google?

0

There are 0 answers