1

Within a Nextjs app, I am using the handleAuth function in @auth0/nextjs-auth0, using the App router, and want to pass a dynamic email address to the handleLogin function. I can pass a predefined email using the login_hint param and have tested this with a hard-coded email const.

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

const email = '[email protected]'

export const GET = handleAuth({
    logout: handleLogout({ returnTo: '/login' }),
    login: handleLogin({ authorizationParams: { login_hint: email }, returnTo: '/profile' }),
});

I now need to retrieve the query parameter from the API URL so that I can pass in dynamic emails; however, I can’t figure out the syntax to get the query parameters.

Does anyone know how to get the request object within the handleAuth function?

I tried to get the API request object within the handleAuth function but it keeps erroring

1 Answer 1

0

I had to access the request object within the handleAuth function to get a query parameter containing an email when a user is signing up for an account. Here's how I did it:

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

export const GET = handleAuth({
  login: handleLogin({
    authorizationParams: { prompt: "login" },
    returnTo: "/dashboard",
  }),
  signup: handleLogin((req) => {
    const url = new URL(req.url ?? "");
    const email = url.searchParams.get("email") ?? "";
    return {
      returnTo: "/dashboard",
      authorizationParams: {
        prompt: "login",
        screen_hint: "signup",
        login_hint: email,
      },
    };
  }),
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.