Skip to content

Get Token

You can use getToken to retrieve the JWT token from a cookie using createBlankSession. This is primarily used to validate or destroy the session, regardless of your use case.

Within the form action, import createBlankSession

src/actions/auth.ts
"use server"
import { cookies } from "next/headers"
import { createBlankSession } from "@/auth"
// Should be defined right after imports
const blankSession = createBlankSession()
// ..
export async function getToken(): string {
const cookieName = blankSession.name
return cookies().get(cookieName)?.value ?? ""
}