mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Add login timeout
This commit is contained in:
parent
2c49848dd7
commit
45baa804e6
@ -46,7 +46,7 @@ export const useAccounts = () => {
|
||||
setVerified({status: "loading"});
|
||||
const selAcc = accounts![selected!];
|
||||
setApiUrl(selAcc.apiUrl);
|
||||
const verif = await loginFunc("refresh", selAcc.refresh_token);
|
||||
const verif = await loginFunc("refresh", selAcc.refresh_token, undefined, 5_000);
|
||||
setVerified(verif.ok ? { status: "ok" } : { status: "error", error: verif.error });
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,11 @@ export const loginFunc = async (
|
||||
action: "register" | "login" | "refresh",
|
||||
body: { username: string; password: string; email?: string } | string,
|
||||
apiUrl?: string,
|
||||
timeout?: number,
|
||||
): Promise<Result<Token, string>> => {
|
||||
try {
|
||||
const controller = timeout !== undefined ? new AbortController() : undefined;
|
||||
if (controller) setTimeout(() => controller.abort(), timeout);
|
||||
const token = await queryFn(
|
||||
{
|
||||
path: ["auth", action, typeof body === "string" && `?token=${body}`],
|
||||
@ -69,6 +72,7 @@ export const loginFunc = async (
|
||||
body: typeof body === "object" ? body : undefined,
|
||||
authenticated: false,
|
||||
apiUrl,
|
||||
abortSignal: controller?.signal,
|
||||
},
|
||||
TokenP,
|
||||
);
|
||||
|
@ -54,7 +54,8 @@ export const queryFn = async <Data,>(
|
||||
body?: object;
|
||||
method: "GET" | "POST" | "DELETE";
|
||||
authenticated?: boolean;
|
||||
apiUrl?: string
|
||||
apiUrl?: string;
|
||||
abortSignal?: AbortSignal;
|
||||
},
|
||||
type?: z.ZodType<Data>,
|
||||
token?: string | null,
|
||||
@ -87,6 +88,7 @@ export const queryFn = async <Data,>(
|
||||
...(token ? { Authorization: token } : {}),
|
||||
...("body" in context ? { "Content-Type": "application/json" } : {}),
|
||||
},
|
||||
signal: "abortSignal" in context ? context.abortSignal : undefined,
|
||||
});
|
||||
} catch (e) {
|
||||
console.log("Fetch error", e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user