Update theme handling and add theme selection dropdown in Navbar.svelte
This commit is contained in:
@@ -3,7 +3,7 @@ import { fail, redirect } from "@sveltejs/kit";
|
||||
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
|
||||
export const load: PageServerLoad = async (event) => {
|
||||
export const load: PageServerLoad = async (event: { locals: { user: any; }; }) => {
|
||||
if (event.locals.user)
|
||||
return {
|
||||
user: event.locals.user,
|
||||
@@ -15,7 +15,7 @@ export const load: PageServerLoad = async (event) => {
|
||||
|
||||
// handle the logout action
|
||||
export const actions: Actions = {
|
||||
default: async (event) => {
|
||||
logout: async (event) => {
|
||||
if (!event.locals.session) {
|
||||
return fail(401);
|
||||
}
|
||||
@@ -28,4 +28,13 @@ export const actions: Actions = {
|
||||
});
|
||||
return redirect(302, "/login");
|
||||
},
|
||||
setTheme: async ( { url, cookies }) => {
|
||||
const theme = url.searchParams.get("theme");
|
||||
if (theme) {
|
||||
cookies.set("colortheme", theme, {
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 24 * 365,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
// wait .5s before redirecting
|
||||
errors = {};
|
||||
goto("/login");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user