fix: 🐛 patch cookie clear process
This commit is contained in:
parent
c38ae17881
commit
b032fe2161
|
@ -1,5 +1,5 @@
|
||||||
import { FreshContext } from '$fresh/server.ts'
|
import { FreshContext } from '$fresh/server.ts'
|
||||||
import { deleteCookie, getCookies, setCookie } from '@std/http/cookie'
|
import { getCookies, setCookie } from '@std/http/cookie'
|
||||||
import { SessionStore } from '../src/session/mod.ts'
|
import { SessionStore } from '../src/session/mod.ts'
|
||||||
|
|
||||||
const instanceToken = crypto.randomUUID() // Instance uuid to reset perform cookie reset on server restart
|
const instanceToken = crypto.randomUUID() // Instance uuid to reset perform cookie reset on server restart
|
||||||
|
@ -17,7 +17,11 @@ export async function handler(request: Request, ctx: FreshContext) {
|
||||||
// Clear outdated cookies
|
// Clear outdated cookies
|
||||||
if (cookies['_INSTANCE'] !== instanceToken) {
|
if (cookies['_INSTANCE'] !== instanceToken) {
|
||||||
for (const cookie in cookies) {
|
for (const cookie in cookies) {
|
||||||
deleteCookie(request.headers, cookie)
|
setCookie(response.headers, {
|
||||||
|
name: cookie,
|
||||||
|
value: '',
|
||||||
|
expires: 0,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
setCookie(response.headers, {
|
setCookie(response.headers, {
|
||||||
name: '_INSTANCE',
|
name: '_INSTANCE',
|
||||||
|
@ -25,11 +29,12 @@ export async function handler(request: Request, ctx: FreshContext) {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'Strict',
|
sameSite: 'Strict',
|
||||||
secure: true,
|
secure: true,
|
||||||
|
expires: 1000 * 2 ** 38, // Never expire
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start session
|
// Start session
|
||||||
if (cookies['_SESSION'] === undefined) {
|
if (cookies['_SESSION'] === undefined || cookies['_SESSION'] === '') {
|
||||||
const session = SessionStore.createSession()
|
const session = SessionStore.createSession()
|
||||||
|
|
||||||
// Set session cookie
|
// Set session cookie
|
||||||
|
|
Loading…
Reference in a new issue