mirror of
https://github.com/ProjectSegfault/website
synced 2026-03-31 02:51:51 +05:30
remove deprecated authentik login and admin dash
This commit is contained in:
@@ -1,10 +1,4 @@
|
||||
import { SvelteKitAuth } from "@auth/sveltekit";
|
||||
import Authentik from "@auth/core/providers/authentik";
|
||||
import { env } from "$env/dynamic/private";
|
||||
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";
|
||||
import {
|
||||
announcements,
|
||||
pubnixUsers,
|
||||
@@ -19,52 +13,6 @@ const agent = new Agent({
|
||||
family: 4
|
||||
});
|
||||
|
||||
const hasAuth =
|
||||
!env.AUTH_CLIENT_ID ||
|
||||
!env.AUTH_CLIENT_SECRET ||
|
||||
!env.AUTH_ISSUER ||
|
||||
!env.AUTH_TRUST_HOST ||
|
||||
!env.AUTH_SECRET
|
||||
? false
|
||||
: true;
|
||||
|
||||
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;
|
||||
}
|
||||
);
|
||||
|
||||
export const fetchGhost = async (action: string, additional?: string) => {
|
||||
return await axios(
|
||||
env.GHOST_URL +
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from "./$types";
|
||||
|
||||
export let data: PageData;
|
||||
</script>
|
||||
|
||||
<h1>{data.title}</h1>
|
||||
<p>Nothing here yet.</p>
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { PageLoad } from "./$types";
|
||||
|
||||
export const load = (() => {
|
||||
return {
|
||||
title: "Admin dashboard"
|
||||
};
|
||||
}) satisfies PageLoad;
|
||||
@@ -1,23 +0,0 @@
|
||||
import { env } from "$env/dynamic/private";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
|
||||
export const load = (async ({ locals }) => {
|
||||
const meta = {
|
||||
title: "Login"
|
||||
};
|
||||
|
||||
const hasAuth =
|
||||
!env.AUTH_CLIENT_ID ||
|
||||
!env.AUTH_CLIENT_SECRET ||
|
||||
!env.AUTH_ISSUER ||
|
||||
!env.AUTH_TRUST_HOST ||
|
||||
!env.AUTH_SECRET
|
||||
? false
|
||||
: true;
|
||||
|
||||
return {
|
||||
session: hasAuth ? await locals.getSession() : undefined,
|
||||
hasAuth,
|
||||
...meta
|
||||
};
|
||||
}) satisfies PageServerLoad;
|
||||
@@ -1,47 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { signIn, signOut } from "@auth/sveltekit/client";
|
||||
import { page } from "$app/stores";
|
||||
import type { PageData } from "./$types";
|
||||
const buttonStyles = "button w-fit";
|
||||
|
||||
export let data: PageData;
|
||||
</script>
|
||||
|
||||
<h1>{data.title}</h1>
|
||||
|
||||
{#if data.hasAuth}
|
||||
{#if Object.keys($page.data.session || {}).length}
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-row items-center gap-1">
|
||||
<span>Signed in as</span><br />
|
||||
<span class="font-extrabold"
|
||||
>{$page?.data?.session?.user?.email}</span
|
||||
>
|
||||
</div>
|
||||
<a href="/admin">Go to admin dashboard</a>
|
||||
<button
|
||||
on:click={() => signOut()}
|
||||
class={buttonStyles}
|
||||
><div class="i-ic:outline-logout" />
|
||||
Sign out</button
|
||||
>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex flex-col gap-4">
|
||||
<span>You are not signed in</span>
|
||||
<button
|
||||
on:click={() => signIn("authentik")}
|
||||
class={buttonStyles}
|
||||
><div class="i-ic:outline-login" />
|
||||
Sign in using Authentik</button
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="flex flex-col gap-4">
|
||||
<span>Authentik is not configured</span>
|
||||
<a href="https://goauthentik.io/docs/installation"
|
||||
>Configure Authentik</a
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user