0.2.94
This commit is contained in:
1 parent
f508b7c882
commit
25d04daaee
12 files changed
+323
-90
No files matched your search
@@ -12,7 +12,7 @@ import * as sessionStore from "@rustpad/session";
|
||||
import { askConfirm, askInput, showMessage } from "@rustpad/modal";
|
||||
import { toast } from "@rustpad/toast";
|
||||
|
||||
const { getAuthToken, setAuthSession, setNickname } = sessionStore;
|
||||
const { getAuthToken, setAuthSession, setNickname, expireAuthSession } = sessionStore;
|
||||
const clearAuthSession = sessionStore.clearAuthSession || (() => {
|
||||
localStorage.removeItem("rustpad:auth-state");
|
||||
localStorage.removeItem("rustpad:auth-token");
|
||||
@@ -343,15 +343,16 @@ function bindLegacyIdentityDialog({ dialog, onIdentity }) {
|
||||
}
|
||||
|
||||
export async function validateCurrentSession() {
|
||||
const expectedSession = Boolean(getAuthToken());
|
||||
try {
|
||||
const session = await api("/api/auth/me");
|
||||
await setAuthSession(session);
|
||||
return session;
|
||||
} catch {
|
||||
if (expectedSession) await clearAuthSession();
|
||||
const result = await api("/api/auth/session", { cache: "no-store" });
|
||||
if (result.authenticated === false && result.session === null) {
|
||||
await expireAuthSession();
|
||||
return null;
|
||||
}
|
||||
if (result.authenticated !== true || !result.session || typeof result.session.nickname !== "string") {
|
||||
throw new Error("Invalid authentication session response.");
|
||||
}
|
||||
await setAuthSession(result.session);
|
||||
return result.session;
|
||||
}
|
||||
|
||||
export async function logoutCurrentSession() {
|
||||
|
||||
Reference in new issue
Block a user