fix: logout 端点添加 domain 参数清除跨域 cookie
- logout 端点清除 cookie 时添加 domain 参数 - 修复 .tlyq.ai 域的 tlyq_session cookie 未正确清除的问题 - cookie 设置时 domain=.tlyq.ai,清除时也必须指定相同 domain
This commit is contained in:
parent
ec4bbcb71b
commit
dbde9a6058
|
|
@ -3,11 +3,12 @@ import { cookies } from 'next/headers'
|
||||||
|
|
||||||
export async function POST() {
|
export async function POST() {
|
||||||
const cookieStore = await cookies()
|
const cookieStore = await cookies()
|
||||||
|
const domain = process.env.COOKIE_DOMAIN || ''
|
||||||
|
|
||||||
// 清除所有相关 cookie
|
// 清除所有相关 cookie(必须指定 domain 以清除跨域 cookie)
|
||||||
cookieStore.set('tlyq_session', '', { maxAge: 0, path: '/' })
|
cookieStore.set('tlyq_session', '', { maxAge: 0, path: '/', domain })
|
||||||
cookieStore.set('session', '', { maxAge: 0, path: '/' })
|
cookieStore.set('session', '', { maxAge: 0, path: '/', domain })
|
||||||
cookieStore.set('oidc_id_token', '', { maxAge: 0, path: '/' })
|
cookieStore.set('oidc_id_token', '', { maxAge: 0, path: '/', domain })
|
||||||
|
|
||||||
// Authelia 4.38 不支持 end_session_endpoint,直接跳转登录页
|
// Authelia 4.38 不支持 end_session_endpoint,直接跳转登录页
|
||||||
// Authelia session 会在 cookie 过期后自动清除
|
// Authelia session 会在 cookie 过期后自动清除
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState, Suspense } from 'react'
|
||||||
import { useSearchParams } from 'next/navigation'
|
import { useSearchParams } from 'next/navigation'
|
||||||
|
|
||||||
export default function LoginPage() {
|
function LoginPageContent() {
|
||||||
const [username, setUsername] = useState('')
|
const [username, setUsername] = useState('')
|
||||||
const [password, setPassword] = useState('')
|
const [password, setPassword] = useState('')
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
|
@ -86,3 +86,11 @@ export default function LoginPage() {
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default function LoginPage() {
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<div className="min-h-screen flex items-center justify-center">加载中...</div>}>
|
||||||
|
<LoginPageContent />
|
||||||
|
</Suspense>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue