This commit is contained in:
2023-01-25 19:11:11 +02:00
parent add264a5d6
commit 07c0cc4a69
117 changed files with 1554 additions and 3593 deletions

View File

@@ -1,27 +1,44 @@
import { SvelteKitAuth } from "@auth/sveltekit"
import Authentik from '@auth/core/providers/authentik';
import { SvelteKitAuth } from "@auth/sveltekit";
import Authentik from "@auth/core/providers/authentik";
import { env } from "$env/dynamic/private";
import statusData from "$lib/statusData";
import map from "$lib/map";
import type { Provider } from "@auth/core/providers";
import type { Profile } from "@auth/core/types";
import { redirect, type Handle } from "@sveltejs/kit";
import { sequence } from "@sveltejs/kit/hooks";
export const handle = SvelteKitAuth({
providers: [
//@ts-ignore
Authentik({
clientId: env.AUTH_CLIENT_ID,
clientSecret: env.AUTH_CLIENT_SECRET,
issuer: env.AUTH_ISSUER
})
]
})
const hasAuth = !env.AUTH_CLIENT_ID || !env.AUTH_CLIENT_SECRET || !env.AUTH_ISSUER || !env.AUTH_TRUST_HOST || !env.AUTH_SECRET ? false : true;
const updateMap = () => {
map.set("data", {
status: statusData,
updated: Math.floor(Date.now() / 1000)
});
};
updateMap();
setInterval(updateMap, 30000);
export const handle: Handle = sequence(
//@ts-ignore
SvelteKitAuth({
providers: [
Authentik({
clientId: env.AUTH_CLIENT_ID,
clientSecret: env.AUTH_CLIENT_SECRET,
issuer: env.AUTH_ISSUER
}) as Provider<Profile>
]
}),
hasAuth ? async ({ event, resolve }) => {
if (event.url.pathname.startsWith("/admin")) {
const session = await event.locals.getSession();
if (!session) {
throw redirect(303, "/login");
}
}
const result = await resolve(event, {
transformPageChunk: ({ html }) => html
});
return result;
} : async ({ event, resolve }) => {
if (event.url.pathname.startsWith("/admin")) {
throw redirect(303, "/login");
}
const result = await resolve(event, {
transformPageChunk: ({ html }) => html
});
return result;
}
);