dcacac18e8
Co-authored-by: Danny Kim <temeddix@gmail.com> Co-committed-by: Danny Kim <temeddix@gmail.com>
13 lines
371 B
TypeScript
13 lines
371 B
TypeScript
export async function retryInvalidToken<
|
|
T extends { status: { success: boolean }; error: string },
|
|
>(attempt: () => Promise<T>, relogin: () => Promise<void>): Promise<T> {
|
|
let result = await attempt();
|
|
if (
|
|
!result.status.success && result.error.includes("invalid_refresh_token")
|
|
) {
|
|
await relogin();
|
|
result = await attempt();
|
|
}
|
|
return result;
|
|
}
|