Enforce roleId checks on all admin page actions

This commit is contained in:
NeilClack
2026-09-10 14:59:32 -05:00
parent 0cb4b2148a
commit 7596937f30
14 changed files with 217 additions and 112 deletions
@@ -1,6 +1,7 @@
import type { PageServerLoad } from './$types';
import { prisma } from '$lib/db';
import { sendMail } from '$lib/server/resend';
import { isStaff } from '$lib/server/roles';
import { error } from '@sveltejs/kit';
function generateLicenseKey(): string {
@@ -18,7 +19,7 @@ export const load: PageServerLoad = async () => {
export const actions = {
createKey: async ({ request, locals }) => {
if (!locals.user) throw error(401, 'Unauthorized');
if (!isStaff(locals)) throw error(403, 'Not authorized');
const formData = await request.formData();
const email = formData.get('email')?.toString()?.trim().toLowerCase();
@@ -60,7 +61,7 @@ export const actions = {
return { success: true, action: 'createKey' };
},
replace: async ({ request, locals }) => {
if (!locals.user) throw error(401, 'Unauthorized');
if (!isStaff(locals)) throw error(403, 'Not authorized');
const formData = await request.formData();
const keyId = formData.get('id')?.toString();