oa-ai/src/app/api/auth/logout/route.ts

19 lines
813 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { NextResponse } from 'next/server'
import { cookies } from 'next/headers'
export async function POST(request: Request) {
const cookieStore = await cookies()
const domain = process.env.COOKIE_DOMAIN || ''
// 清除所有相关 cookie必须指定 domain 以清除跨域 cookie
cookieStore.set('tlyq_session', '', { maxAge: 0, path: '/', domain })
cookieStore.set('session', '', { maxAge: 0, path: '/', domain })
cookieStore.set('oidc_id_token', '', { maxAge: 0, path: '/', domain })
// Authelia 4.38 不支持 end_session_endpoint直接跳转登录页
// Authelia session 会在 cookie 过期后自动清除
// 从请求 URL 动态获取 base URL避免硬编码 localhost
const { origin } = new URL(request.url)
return NextResponse.redirect(new URL('/login', origin))
}