Link Multiple Google Accounts to single user (Next.js)

I’m following this question’s solution:

In my SPA, a user signs in with Google. I then want them to be able to link another Google account if they have one (I have multiple for example).

I route the user to /api/auth/login?type=google-oauth2 where I check for type for account linking, and then set connection in authorizationParams before calling handleLogin. It immediately uses the existing google oauth login and routes the user instead of giving them an option to login and link another google account.

Here’s my […auth0.js]

import { handleAuth, handleLogin, handleLogout } from '@auth0/nextjs-auth0';

export default handleAuth({
  async login(req, res) {

    // Check for account link request.
    if (req.query.type) {
      const authorizationParams = {
        connection: req.query.type
      }
      await handleLogin(req, res, {
        returnTo: "/some-path",
        authorizationParams
      })
    }
    else {
      await handleLogin(req, res, {
        returnTo: "/some-path",
      });
    }

    
  },
  async logout(req, res) {
    await handleLogout(req, res, {
      returnTo: "/",
    });
  },
});

How can I force a new Google login?

I was able to fix this by changing authorizationParams to:

const authorizationParams = {
        connection: req.query.type,
        prompt: "login"
      }
1 Like

Thanks for sharing that with the rest of community!