Next.js Discord

Discord Forum

Getting user data after signing in using NextAuth

Unanswered
Broad-snouted Caiman posted this in #help-forum
Open in Discord
Broad-snouted CaimanOP
I'm implementing authentication for my NextJS app using NextAuth v5 following the instructions here: https://nextjs.org/learn/dashboard-app/adding-authentication
The tutorial ends after successfully logging into the app. Now I want to get additional user data (first name, last name, profile picture etc.) from my database to display in my app, how can I achieve that? I tried calling the auth() function imported from auth.ts but the returned auth().user object is empty:
import { auth } from "@/auth";

export default async function Page() {
  const session = await auth();
  console.log(JSON.stringify(session));

Output:
{"user":{},"expires":"2024-01-25T10:09:08.419Z"}

2 Replies

did you sign in yet?
@aardani did you sign in yet?
Broad-snouted CaimanOP
Yes I did. I tried signing out then signing in again but no luck