Nextjs-auth0 /api/auth/me route doesn't return as many details as expected

  • Which SDK this is regarding: nextjs-auth0
  • SDK Version: 1.0.0-beta.0, 0.16.0
  • Platform Version: e.g. Node v15.0.1
  • Code Snippets/Error Messages/Supporting Details/Screenshots:

I’m new to Auth0 so this might be a newb question. When I look at a user’s raw JSON directly in Auth0, I can see various details like email, email_verified, identities, etc. But when accessing the /api/auth/me API route in the Next.js-Auth0 SDK, it only returns a few parameters like nickname, name, and picture, among a few others.

Is this an issue with configuration on admin side? I also noticed that when I register a user, the email address is put into the “name” field for some reason. At the very least, I need to be able to fetch the user’s email and metadata as part of the profile. Any assistance/advice is appreciated.

Thanks ahead of time for the help!

1 Like

UPDATE:
Seems like I’ve found a starting point. Still not clear whether it’s my user error or if there’s an inconsistency, but the details can be found here in this issue I filed in the repo:

https://github.com/auth0/nextjs-auth0/issues/240

Essentially, I had to manually specify authorizationParams for the login:

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

export default handleAuth({
  async login(req, res) {
    try {
      await handleLogin(req, res, { 
        returnTo: '/dashboard',
        authorizationParams: {
          response_type: 'code',
          scope: 'openid profile email',
        }
      });
    } catch (error) {
      res.status(error.status || 500).end(error.message);
    }
  }
});

I pinged the repo maintainer regarding your issue so they should look at that shortly!

I figured out the problem. It was user error. Derp derp.

When running Auth0 on Next.js, you have the ability to set various parameters via environment variables. I had completely forgotten I’d set the scope in there.

So my .env.local file had this:

...
AUTH0_SCOPE="openid profile"
...

And subsequently, the default behavior was not showing the user’s email. However, it looks like specifying it explicitly in the API routes does override the environment variable.

const cryptoRandomString = require('crypto-random-string');
import { handleAuth, handleLogin, handleProfile } from '@auth0/nextjs-auth0';

export default handleAuth({
  async login(req, res) {
    try {
      await handleLogin(req, res, { 
        returnTo: '/dashboard',
        authorizationParams: {
          response_type: 'code',
          scope: 'openid profile email',
        }
      });
    } catch (error) {
      res.status(error.status || 500).end(error.message);
    }
  },
  ...

The above does return the user’s email information at /api/auth/me regardless of how the ENV variables were set up.

1 Like

Perfect glad you have figured it out and thanks for sharing with the rest of community!