import type { Adapter } from "../../adapters" ; import type { InternalOptions } from "../../lib/types" ; import type { OutgoingResponse } from ".." ; import type { SessionStore } from "../lib/cookie" ; /** Handle requests to /api/auth/signout */ export default async function signout ( params ) { const { options , sessionStore } = params ; const { adapter , events , jwt , callbackUrl , logger , session } = options ; const sessionToken = sessionStore ?. value ; if ( ! sessionToken ) { return { redirect : callbackUrl } ; } if ( session . strategy === "jwt" ) { try { const decodedJwt = await jwt . decode ( { ... jwt , token : sessionToken } ) ; await events . signOut ?. ( { token : decodedJwt } ) ; } catch ( error ) { logger . error ( "SIGNOUT_ERROR" , error ) ; } } else { try { const session = await ( adapter as Adapter ) . deleteSession ( sessionToken ) ; await events . signOut ?. ( { session } ) ; } catch ( error ) { logger . error ( "SIGNOUT_ERROR" , error as Error ) ; } } const sessionCookies = sessionStore . clean ( ) ; return { redirect : callbackUrl , cookies : sessionCookies } ; }