Auth0 useUser hook returns empty user object

Hey guys,
i recently added Auth0 to my personal project. After a lot of reasearch I found a working solution to callback to the right page. I added a custom a custom action:

/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
  api.redirect.sendUserTo("https://localhost/");
};

Now this works.

But the useUser hook is returning an empty user object:

import Header from '@/components/Header'
import Tile from '@/components/Tile'
import { useUser, withPageAuthRequired } from '@auth0/nextjs-auth0/client'


export default function Home() {
  const {user, error, isLoading} = useUser();
  
  if (isLoading) return <div>Loading...</div>
  if (error) return <div>{error.message}</div>
  if (user) return <div>{user.id}</div>
  return (
    <main className='min-h-screen'>
      <Header page="/home"/>
    </main>
  )
}

I can log in at the route /api/auth/login. After that i shortly can see the loading, after that the page renders. So I guess the request is working.

This is my .env file:

AUTH0_SECRET="SECRET"
AUTH0_BASE_URL="https://localhost"
AUTH0_ISSUER_BASE_URL="https://binaeg.eu.auth0.com"
AUTH0_CLIENT_ID="OJBZNdENMaRypJ8cm5bMFuHE35EJGT5l"
AUTH0_CLIENT_SECRET="SECRET"
AUTH0_SCOPE="openid profile"

Do you have any idea how to get the user object?

Thank you in advance.
Let me know if you need something else.

Simon

Hey there!

As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!

Did you ever figure it out? I’m struggling to get back a user, /api/auth/me is returning 204 and user is undefined

1 Like