fix qr auth
This commit is contained in:
@@ -65,7 +65,7 @@ interface AuthContextValue {
|
||||
beginTotpLogin: (recipient: string) => Promise<string>;
|
||||
verifyTotpLogin: (totpChallengeToken: string, code: string) => Promise<AuthTokens>;
|
||||
completePin: (sessionId: string, pin: string) => Promise<void>;
|
||||
applyLoginAuth: (auth: AuthTokens) => Promise<AuthTokens>;
|
||||
applyLoginAuth: (auth: Omit<AuthTokens, 'user'> & { user?: PublicUser }) => Promise<Omit<AuthTokens, 'user'> & { user?: PublicUser }>;
|
||||
applyUserPatch: (patch: Partial<PublicUser>) => void;
|
||||
register: (data: { displayName: string; login: string; password: string }) => Promise<void>;
|
||||
refreshProfile: () => Promise<void>;
|
||||
@@ -88,10 +88,12 @@ function readCachedUserProfile(): PublicUser | null {
|
||||
}
|
||||
}
|
||||
|
||||
function persistPartialAuth(auth: AuthTokens) {
|
||||
function persistPartialAuth(auth: Omit<AuthTokens, 'user'> & { user?: PublicUser }) {
|
||||
window.localStorage.setItem(AUTH_REFRESH_KEY, auth.refreshToken);
|
||||
window.localStorage.setItem(AUTH_SESSION_KEY, auth.sessionId);
|
||||
cacheUserProfile(auth.user);
|
||||
if (auth.user) {
|
||||
cacheUserProfile(auth.user);
|
||||
}
|
||||
}
|
||||
|
||||
function applySessionState(
|
||||
@@ -625,13 +627,20 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
);
|
||||
|
||||
const applyLoginAuth = React.useCallback(
|
||||
async (auth: AuthTokens) => {
|
||||
async (auth: Omit<AuthTokens, 'user'> & { user?: PublicUser }) => {
|
||||
if (auth.pinVerified) {
|
||||
await establishSession(auth);
|
||||
if (!auth.user) {
|
||||
const user = await fetchAuthSession(auth.accessToken).then((session) => session.user);
|
||||
await establishSession({ ...auth, user });
|
||||
} else {
|
||||
await establishSession(auth);
|
||||
}
|
||||
} else {
|
||||
persistPartialAuth(auth);
|
||||
if (auth.user) {
|
||||
setUser(auth.user);
|
||||
}
|
||||
setHasStoredSession(true);
|
||||
activatePinLock(auth.sessionId);
|
||||
}
|
||||
return auth;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user