Skip to content

Get Session

getSession allows you to retrieve the user session object, which enables you to perform logic based on it. A common use case is to protect certain routes or display user information, such as a name or profile picture.

Within the form action, import validateSession then use getToken to get the token value.

src/actions/auth.ts
"use server"
import { cookies } from "next/headers"
import { validateSession } from "@/auth"
// ...
export async function getSession() {
const token = getToken()
const session = await validateSession(token)
return session.session
}