forked from mirrors/pronouns.cc
fix: redirect settings pages to login if the user is not logged in
This commit is contained in:
parent
ff75075b81
commit
86f272a365
1 changed files with 27 additions and 19 deletions
|
@ -6,11 +6,13 @@ import {
|
||||||
type MeUser,
|
type MeUser,
|
||||||
} from "$lib/api/entities";
|
} from "$lib/api/entities";
|
||||||
import { apiFetchClient } from "$lib/api/fetch";
|
import { apiFetchClient } from "$lib/api/fetch";
|
||||||
|
import { redirect } from "@sveltejs/kit";
|
||||||
import type { LayoutLoad } from "./$types";
|
import type { LayoutLoad } from "./$types";
|
||||||
|
|
||||||
export const ssr = false;
|
export const ssr = false;
|
||||||
|
|
||||||
export const load = (async ({ parent }) => {
|
export const load = (async ({ parent }) => {
|
||||||
|
try {
|
||||||
const user = await apiFetchClient<MeUser>("/users/@me");
|
const user = await apiFetchClient<MeUser>("/users/@me");
|
||||||
const warnings = await apiFetchClient<Warning[]>("/auth/warnings?all=true");
|
const warnings = await apiFetchClient<Warning[]>("/auth/warnings?all=true");
|
||||||
|
|
||||||
|
@ -33,4 +35,10 @@ export const load = (async ({ parent }) => {
|
||||||
invitesEnabled,
|
invitesEnabled,
|
||||||
warnings,
|
warnings,
|
||||||
};
|
};
|
||||||
|
} catch (e) {
|
||||||
|
if ((e as APIError).code !== ErrorCode.InternalServerError) {
|
||||||
|
throw redirect(303, "/auth/login");
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}) satisfies LayoutLoad;
|
}) satisfies LayoutLoad;
|
||||||
|
|
Loading…
Reference in a new issue