1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-05 13:15:18 +02:00

Admin toggle checkbox fix

This commit is contained in:
Sean Morley 2024-05-25 13:40:32 +00:00
parent 524cdc199c
commit 8f0ae40534

View file

@ -98,6 +98,13 @@ export const actions: Actions = {
const formData = await event.request.formData(); const formData = await event.request.formData();
const formUsername = formData.get("username"); const formUsername = formData.get("username");
let username = formUsername?.toString().toLocaleLowerCase(); let username = formUsername?.toString().toLocaleLowerCase();
let role = formData.get("role");
if (!role) {
role = "user";
} else {
role = "admin";
}
console.log("role", role);
if (typeof formUsername !== "string") { if (typeof formUsername !== "string") {
return fail(400, { message: "Invalid username" }); return fail(400, { message: "Invalid username" });
@ -187,18 +194,11 @@ export const actions: Actions = {
last_name: lastName, last_name: lastName,
hashed_password: hashedPassword, hashed_password: hashedPassword,
signup_date: new Date(), signup_date: new Date(),
role: "admin", role: role,
last_login: new Date(), last_login: new Date(),
} as DatabaseUser) } as DatabaseUser)
.execute(); .execute();
const session = await lucia.createSession(userId, {});
const sessionCookie = lucia.createSessionCookie(session.id);
event.cookies.set(sessionCookie.name, sessionCookie.value, {
path: ".",
...sessionCookie.attributes,
});
return { success: true }; return { success: true };
}, },
}; };