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
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.
đź’ˇ
By default, GET requests to the session endpoint will automatically return the headers to prevent caching.