mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
fix: auth post (#627)
Co-authored-by: Igor Loskutov <igor.loskutoff@gmail.com>
This commit is contained in:
@@ -90,7 +90,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||||||
// not useEffect, we need it ASAP
|
// not useEffect, we need it ASAP
|
||||||
// apparently, still no guarantee this code runs before mutations are fired
|
// apparently, still no guarantee this code runs before mutations are fired
|
||||||
configureApiAuth(
|
configureApiAuth(
|
||||||
contextValue.status === "authenticated" ? contextValue.accessToken : null,
|
contextValue.status === "authenticated"
|
||||||
|
? contextValue.accessToken
|
||||||
|
: contextValue.status === "loading"
|
||||||
|
? undefined
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ export const $api = createFetchClient<paths>(client);
|
|||||||
let currentAuthToken: string | null | undefined = undefined;
|
let currentAuthToken: string | null | undefined = undefined;
|
||||||
|
|
||||||
// the function contract: lightweight, idempotent
|
// the function contract: lightweight, idempotent
|
||||||
export const configureApiAuth = (token: string | null) => {
|
export const configureApiAuth = (token: string | null | undefined) => {
|
||||||
|
// watch only for the initial loading; "reloading" state assumes token presence/absence
|
||||||
|
if (token === undefined && currentAuthToken !== undefined) return;
|
||||||
currentAuthToken = token;
|
currentAuthToken = token;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user