frontend: initial commit

This commit is contained in:
$(pass /github/name)
2024-09-07 13:36:15 +02:00
parent 4d6938de96
commit 147b8c0afd
22 changed files with 1804 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import { BASE_API_URI } from "$lib/utils/constants";
import { fail, redirect } from "@sveltejs/kit";
/** @type {import('./$types').PageServerLoad} */
export async function load({ locals }) {
// redirect user if not logged in
if (!locals.user) {
throw redirect(302, `/auth/login?next=/auth/logout`);
}
}
/** @type {import('./$types').Actions} */
export const actions = {
default: async ({ fetch, cookies }) => {
/** @type {RequestInit} */
const requestInitOptions = {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
Cookie: `jwt=${cookies.get("jwt")}`,
},
};
const res = await fetch(
`${BASE_API_URI}/users/backend/logout/`,
requestInitOptions
);
if (!res.ok) {
const response = await res.json();
const errors = [];
errors.push({ error: response.error, id: 0 });
return fail(400, { errors: errors });
}
// eat the cookie
cookies.delete("jwt", { path: "/" });
// redirect the user
throw redirect(302, "/auth/login");
},
};