Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions web/src/lib/keycast_api.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ export class KeycastApi {
});

if (!response.ok) {
if (response.status === 401) {
if (typeof window !== "undefined") {
const currentPath = `${window.location.pathname}${window.location.search}`;
const safeRedirect = currentPath.startsWith("/") ? currentPath : "/";
const loginUrl = `/login?redirect=${encodeURIComponent(safeRedirect)}`;

if (!window.location.pathname.startsWith("/login")) {
window.location.assign(loginUrl);
}
}

throw new ApiError("Authentication required", response.status);
}

// Try to get the error message from the response body
let errorMessage: string;
try {
Expand Down
Loading