session auto refresh blink

This commit is contained in:
Igor Loskutov
2025-09-03 08:33:13 -04:00
parent cff662709d
commit 1b22eabb3f
4 changed files with 28 additions and 32 deletions

View File

@@ -10,6 +10,7 @@ import { SessionAutoRefresh } from "./SessionAutoRefresh";
type AuthContextType = (
| { status: "loading" }
| { status: "refreshing" }
| { status: "unauthenticated"; error?: string }
| {
status: "authenticated";
@@ -30,23 +31,25 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
const customSession = session ? assertExtendedTokenAndUserId(session) : null;
const contextValue: AuthContextType = {
...(status === "loading"
...(status === "loading" && !customSession
? { status }
: status === "authenticated" && customSession?.accessToken
? {
status,
accessToken: customSession.accessToken,
accessTokenExpires: customSession.accessTokenExpires,
user: customSession.user,
}
: status === "authenticated" && !customSession?.accessToken
? (() => {
console.warn(
"illegal state: authenticated but have no session/or access token. ignoring",
);
return { status: "unauthenticated" as const };
})()
: { status: "unauthenticated" as const }),
: status === "loading" && customSession
? { status: "refreshing" as const }
: status === "authenticated" && customSession?.accessToken
? {
status,
accessToken: customSession.accessToken,
accessTokenExpires: customSession.accessTokenExpires,
user: customSession.user,
}
: status === "authenticated" && !customSession?.accessToken
? (() => {
console.warn(
"illegal state: authenticated but have no session/or access token. ignoring",
);
return { status: "unauthenticated" as const };
})()
: { status: "unauthenticated" as const }),
update,
signIn,
signOut,