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"});
|
setVerified({status: "loading"});
|
||||||
const selAcc = accounts![selected!];
|
const selAcc = accounts![selected!];
|
||||||
setApiUrl(selAcc.apiUrl);
|
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 });
|
setVerified(verif.ok ? { status: "ok" } : { status: "error", error: verif.error });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +60,11 @@ export const loginFunc = async (
|
|||||||
action: "register" | "login" | "refresh",
|
action: "register" | "login" | "refresh",
|
||||||
body: { username: string; password: string; email?: string } | string,
|
body: { username: string; password: string; email?: string } | string,
|
||||||
apiUrl?: string,
|
apiUrl?: string,
|
||||||
|
timeout?: number,
|
||||||
): Promise<Result<Token, string>> => {
|
): Promise<Result<Token, string>> => {
|
||||||
try {
|
try {
|
||||||
|
const controller = timeout !== undefined ? new AbortController() : undefined;
|
||||||
|
if (controller) setTimeout(() => controller.abort(), timeout);
|
||||||
const token = await queryFn(
|
const token = await queryFn(
|
||||||
{
|
{
|
||||||
path: ["auth", action, typeof body === "string" && `?token=${body}`],
|
path: ["auth", action, typeof body === "string" && `?token=${body}`],
|
||||||
@ -69,6 +72,7 @@ export const loginFunc = async (
|
|||||||
body: typeof body === "object" ? body : undefined,
|
body: typeof body === "object" ? body : undefined,
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
apiUrl,
|
apiUrl,
|
||||||
|
abortSignal: controller?.signal,
|
||||||
},
|
},
|
||||||
TokenP,
|
TokenP,
|
||||||
);
|
);
|
||||||
|
@ -54,7 +54,8 @@ export const queryFn = async <Data,>(
|
|||||||
body?: object;
|
body?: object;
|
||||||
method: "GET" | "POST" | "DELETE";
|
method: "GET" | "POST" | "DELETE";
|
||||||
authenticated?: boolean;
|
authenticated?: boolean;
|
||||||
apiUrl?: string
|
apiUrl?: string;
|
||||||
|
abortSignal?: AbortSignal;
|
||||||
},
|
},
|
||||||
type?: z.ZodType<Data>,
|
type?: z.ZodType<Data>,
|
||||||
token?: string | null,
|
token?: string | null,
|
||||||
@ -87,6 +88,7 @@ export const queryFn = async <Data,>(
|
|||||||
...(token ? { Authorization: token } : {}),
|
...(token ? { Authorization: token } : {}),
|
||||||
...("body" in context ? { "Content-Type": "application/json" } : {}),
|
...("body" in context ? { "Content-Type": "application/json" } : {}),
|
||||||
},
|
},
|
||||||
|
signal: "abortSignal" in context ? context.abortSignal : undefined,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Fetch error", e);
|
console.log("Fetch error", e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user