1
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { AuthRefreshResponse } from '../../packages/shared/src/contracts/auth';
|
||||
import {
|
||||
API_RESPONSE_ENVELOPE_HEADER,
|
||||
API_RESPONSE_ENVELOPE_VERSION,
|
||||
@@ -7,7 +8,6 @@ import {
|
||||
parseApiErrorMessage,
|
||||
unwrapApiResponse,
|
||||
} from '../../packages/shared/src/http';
|
||||
import type { AuthRefreshResponse } from '../../packages/shared/src/contracts/auth';
|
||||
|
||||
const ACCESS_TOKEN_KEY = 'genarrative.auth.access-token.v1';
|
||||
const AUTO_AUTH_USERNAME_KEY = 'genarrative.auth.auto-username.v1';
|
||||
@@ -487,6 +487,16 @@ async function refreshAccessToken() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function ensureStoredAccessToken() {
|
||||
const currentToken = getStoredAccessToken();
|
||||
if (currentToken) {
|
||||
return currentToken;
|
||||
}
|
||||
|
||||
// AuthGate 恢复会话时可能只有 HttpOnly refresh cookie,本地尚无 access token。
|
||||
return refreshAccessToken();
|
||||
}
|
||||
|
||||
export async function fetchWithApiAuth(
|
||||
input: string,
|
||||
init: RequestInit = {},
|
||||
|
||||
Reference in New Issue
Block a user