Fix refresh token 403 first time

This commit is contained in:
Zoe Roux 2023-12-05 01:39:27 +01:00
parent eed764c6e0
commit 87fdc1a444

View File

@ -69,10 +69,11 @@ export const getTokenWJ = async (
if (account === undefined) account = getCurrentAccount();
if (!account) return [null, null] as const;
let token = account.token;
if (account.token.expire_at <= new Date(new Date().getTime() + 10 * 1000)) {
console.log("refreshing token...");
try {
const token = await queryFn(
token = await queryFn(
{
path: ["auth", "refresh", `?token=${account.token.refresh_token}`],
method: "GET",
@ -86,7 +87,7 @@ export const getTokenWJ = async (
console.error("Error refreshing token durring ssr:", e);
}
}
return [`${account.token.token_type} ${account.token.access_token}`, account.token] as const;
return [`${token.token_type} ${token.access_token}`, token] as const;
}
// Do not cache promise durring ssr.