Fix Super admins being blocked from editing proclamations
This commit is contained in:
@@ -13,8 +13,16 @@ const ProclamationSchema = z.object({
|
||||
content: z.string().optional().default('')
|
||||
});
|
||||
|
||||
function isSuper(locals: App.Locals): boolean {
|
||||
return ((locals.user as { roleId?: number } | null)?.roleId ?? 4) <= 1;
|
||||
async function isSuper(locals: App.Locals): Promise<boolean> {
|
||||
if (!locals.user?.id) return false;
|
||||
|
||||
// The Better Auth session user does not include `roleId`, so read the
|
||||
// current role from the database.
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: locals.user.id },
|
||||
select: { roleId: true }
|
||||
});
|
||||
return (user?.roleId ?? 4) <= 1;
|
||||
}
|
||||
|
||||
export const load: PageServerLoad = async ({ locals }) => {
|
||||
@@ -40,7 +48,7 @@ export const load: PageServerLoad = async ({ locals }) => {
|
||||
const records = proclamations as unknown as Record<string, unknown>[];
|
||||
|
||||
// Strip content from non-Super users
|
||||
if (!isSuper(locals)) {
|
||||
if (!(await isSuper(locals))) {
|
||||
for (const record of records) {
|
||||
delete record.content;
|
||||
}
|
||||
@@ -55,7 +63,7 @@ export const actions = {
|
||||
return { success: false, action: 'upsert', error: 'Unauthorized' };
|
||||
}
|
||||
|
||||
if (!isSuper(locals)) {
|
||||
if (!(await isSuper(locals))) {
|
||||
return {
|
||||
success: false,
|
||||
action: 'upsert',
|
||||
@@ -98,7 +106,7 @@ export const actions = {
|
||||
return { success: true, action: 'upsert' };
|
||||
},
|
||||
delete: async ({ request, locals }) => {
|
||||
if (!isSuper(locals)) {
|
||||
if (!(await isSuper(locals))) {
|
||||
return {
|
||||
success: false,
|
||||
action: 'delete',
|
||||
|
||||
Reference in New Issue
Block a user