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