token存储转移到cookie
Publish to npm / publish (push) Failing after 9s

This commit is contained in:
2026-05-04 16:57:08 +08:00
parent 713b8ae31e
commit fa4032f239
+10 -5
View File
@@ -89,7 +89,7 @@ export class SimApiCore {
endpoints: {default: ''}, endpoints: {default: ''},
defaultEndpoint: 'default', defaultEndpoint: 'default',
businessCallback: { businessCallback: {
401: () => localStorage.removeItem(this.auth.token_name), 401: () => this.removeToken(),
common: () => { common: () => {
}, },
}, },
@@ -167,17 +167,22 @@ export class SimApiCore {
} }
getToken(): string { 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 { 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 { 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 { genS4(): string {
return (((1 + Math.random()) * 0x10000 * Date.parse(new Date().toString())) | 0) return (((1 + Math.random()) * 0x10000 * Date.parse(new Date().toString())) | 0)
.toString(16) .toString(16)
@@ -258,7 +263,7 @@ export class SimApiCore {
if (this.debug) { if (this.debug) {
headers['Query-Id'] = queryId 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 const url = this.getEndpoint(endpointKey) + uri