How to get the user's data right after login/signup?

Please include the following information in your post:

  • Which SDK this is regarding: auth0-nextjs
  • SDK Version: 1.3.0
  • Platform Version: Next.js 10.1
  • Code Snippets/Error Messages/Supporting Details/Screenshots:

How can I get the user’s details right after the user logs in / signs up?
that is, right when the handleLogin() method is called, I want the user’s data. How can I get it?

Hi @faisalsayed10,

Welcome to the Community!

You can use the useUser hook to get user data: Auth0 Next.js SDK Quickstarts: Login

import React from 'react';
import { useUser } from '@auth0/nextjs-auth0';

export default function Profile() {
  const { user, error, isLoading } = useUser();

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>{error.message}</div>;
  
  return (
    user && (
      <div>
        <img src={user.picture} alt={user.name} />
        <h2>{user.name}</h2>
        <p>{user.email}</p>
      </div>
    )
  );
}

Your app will need to be wrapped in the UserProvider component: Auth0 Next.js SDK Quickstarts: Login

import React from 'react';
import { UserProvider } from '@auth0/nextjs-auth0';

export default function App({ Component, pageProps }) {
  return (
    <UserProvider>
      <Component {...pageProps} />
    </UserProvider>
  );
}

You can also get user data from the /api/auth/me route.

You can find an example of this in the Next.js quickstart:

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.