mirror of
https://github.com/ProjectSegfault/website.git
synced 2024-12-22 21:19:51 +05:30
add auth to form actions
This commit is contained in:
parent
a95b761ce4
commit
061961e26f
@ -4,7 +4,10 @@ import { fail } from "@sveltejs/kit";
|
|||||||
import db from "$lib/db";
|
import db from "$lib/db";
|
||||||
|
|
||||||
export const actions: Actions = {
|
export const actions: Actions = {
|
||||||
add: async ({ request }) => {
|
add: async ({ request, locals }) => {
|
||||||
|
if (!await locals.getSession()) {
|
||||||
|
return fail(401, { addError: true, addMessage: "You must be logged in to post an announcement." });
|
||||||
|
} else {
|
||||||
const Announcements = db.model("Announcements");
|
const Announcements = db.model("Announcements");
|
||||||
|
|
||||||
const formData = await request.formData();
|
const formData = await request.formData();
|
||||||
@ -33,8 +36,13 @@ export const actions: Actions = {
|
|||||||
|
|
||||||
return { addSuccess: true, addMessage: "Your announcement has been posted." };
|
return { addSuccess: true, addMessage: "Your announcement has been posted." };
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
delete: async () => {
|
delete: async ({ locals }) => {
|
||||||
|
if (!await locals.getSession()) {
|
||||||
|
return fail(401, { deleteError: true, deleteMessage: "You must be logged in to delete an announcement." });
|
||||||
|
} else {
|
||||||
const Announcements = db.model("Announcements");
|
const Announcements = db.model("Announcements");
|
||||||
|
|
||||||
await Announcements.sync();
|
await Announcements.sync();
|
||||||
@ -43,4 +51,5 @@ export const actions: Actions = {
|
|||||||
|
|
||||||
return { deleteSuccess: true, deleteMessage: "Your announcement has been deleted." };
|
return { deleteSuccess: true, deleteMessage: "Your announcement has been deleted." };
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user