Skip to content
需要从 NextAuth.js v4 升级到最新版本吗?请查阅 版本升级指南

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.