From fa4032f2390071afe827cfbeecb9b531c584d9bb Mon Sep 17 00:00:00 2001 From: xRain Date: Mon, 4 May 2026 16:57:08 +0800 Subject: [PATCH] =?UTF-8?q?token=E5=AD=98=E5=82=A8=E8=BD=AC=E7=A7=BB?= =?UTF-8?q?=E5=88=B0cookie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/simapi.core.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/simapi.core.ts b/src/simapi.core.ts index c709b36..bc66c90 100644 --- a/src/simapi.core.ts +++ b/src/simapi.core.ts @@ -89,7 +89,7 @@ export class SimApiCore { endpoints: {default: ''}, defaultEndpoint: 'default', businessCallback: { - 401: () => localStorage.removeItem(this.auth.token_name), + 401: () => this.removeToken(), common: () => { }, }, @@ -167,17 +167,22 @@ export class SimApiCore { } getToken(): string { - return localStorage.getItem(this.auth.token_name) ?? '' + const name = this.auth.token_name + const match = document.cookie.match(new RegExp(`(?:^|;)\\s?${name}=([^;]+)`)) + return match ? match[1] : '' } setToken(token: string): void { - localStorage.setItem(this.auth.token_name, token) + const name = this.auth.token_name + document.cookie = `${name}=${token}; path=/; secure; samesite=none` } removeToken(): void { - localStorage.removeItem(this.auth.token_name) + const name = this.auth.token_name + document.cookie = `${name}=; path=/; max-age=0; secure; samesite=none` } + genS4(): string { return (((1 + Math.random()) * 0x10000 * Date.parse(new Date().toString())) | 0) .toString(16) @@ -258,7 +263,7 @@ export class SimApiCore { if (this.debug) { headers['Query-Id'] = queryId - console.log('[REQUEST*]', queryId, '->', uri, 'AUTH:', localStorage.getItem(this.auth.token_name)) + console.log('[REQUEST*]', queryId, '->', uri, 'AUTH:', this.getToken()) } const url = this.getEndpoint(endpointKey) + uri