mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
This commit is contained in:
parent
0ec019f959
commit
4cafc41b88
11 changed files with 192 additions and 77 deletions
|
|
@ -14,7 +14,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
|||
context.locals.session = isAuthed.session
|
||||
|
||||
const user = await prismaClient.users.findUnique({
|
||||
select: { roles: { select: { roles: { select: { permissions: true } } } } },
|
||||
select: { roles: { select: { roleName: true, roles: { select: { permissions: true } } } } },
|
||||
where: { id: isAuthed.user.id }
|
||||
})
|
||||
const permissions = (user?.roles.map((r) => r.roles.permissions).flat() as string[]) ?? []
|
||||
|
|
@ -22,6 +22,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
|||
|
||||
context.locals.permissions = permissions
|
||||
context.locals.pages = pages
|
||||
context.locals.roles = user?.roles.map((r) => r.roleName) ?? []
|
||||
} else {
|
||||
context.locals.user = null
|
||||
context.locals.session = null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue