Skip to content
Migrating from NextAuth.js v4? Read our migration guide.

Get Session

Once a user is logged in, you often want to get the session object in order to use the data in some way. A common use-case is to show their profile picture or display some other user information.

./components/UserAvatar.tsx
import { auth } from "../auth"
 
export default async function UserAvatar() {
  const session = await auth()
 
  if (!session?.user) return null
 
  return (
    <div>
      <img src={session.user.image} alt="User Avatar" />
    </div>
  )
}

If you’d like to extend your session with more fields from your OAuth provider, for example, please check out our “extending the session” guide.

Auth.js © Balázs Orbán and Team - 2024