R61 A1-A6:Auth token refresh 主动续期
这个提交包含在:
+10
-7
@@ -1,4 +1,4 @@
|
||||
import { ApiError, type ApiErrorBody, type ApiSuccess } from "./types";
|
||||
import { ApiError, SessionExpiredError, type ApiErrorBody, type ApiSuccess } from "./types";
|
||||
|
||||
type AccessTokenGetter = () => string | null;
|
||||
type RefreshAccessToken = () => Promise<string | null>;
|
||||
@@ -79,6 +79,13 @@ async function getRefreshedToken(): Promise<string | null> {
|
||||
return refreshPromise;
|
||||
}
|
||||
|
||||
function throwSessionExpired(): never {
|
||||
if (clearSession) {
|
||||
clearSession();
|
||||
}
|
||||
throw new SessionExpiredError();
|
||||
}
|
||||
|
||||
async function sendRequest<T>(
|
||||
path: string,
|
||||
options: ApiRequestOptions,
|
||||
@@ -118,9 +125,7 @@ async function sendRequest<T>(
|
||||
});
|
||||
}
|
||||
|
||||
if (clearSession) {
|
||||
clearSession();
|
||||
}
|
||||
throwSessionExpired();
|
||||
}
|
||||
|
||||
const payload = await safeParseJson(response);
|
||||
@@ -210,9 +215,7 @@ export async function apiRequestBlob(
|
||||
});
|
||||
}
|
||||
|
||||
if (clearSession) {
|
||||
clearSession();
|
||||
}
|
||||
throwSessionExpired();
|
||||
}
|
||||
|
||||
const payload = await safeParseJson(response);
|
||||
|
||||
@@ -19,6 +19,7 @@ export type LoginRequest = {
|
||||
|
||||
export type LoginResponse = {
|
||||
accessToken: string;
|
||||
expiresIn?: number;
|
||||
mustChangePassword?: boolean;
|
||||
};
|
||||
|
||||
@@ -73,6 +74,17 @@ export function isApiError(value: unknown): value is ApiError {
|
||||
return value instanceof ApiError;
|
||||
}
|
||||
|
||||
export class SessionExpiredError extends Error {
|
||||
constructor(message = "会话已过期") {
|
||||
super(message);
|
||||
this.name = "SessionExpiredError";
|
||||
}
|
||||
}
|
||||
|
||||
export function isSessionExpiredError(value: unknown): value is SessionExpiredError {
|
||||
return value instanceof SessionExpiredError;
|
||||
}
|
||||
|
||||
|
||||
export type WorkflowTaskSummary = {
|
||||
id: string;
|
||||
|
||||
在新工单中引用
屏蔽一个用户