mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-15 01:14:27 -05:00
feat: add administrator guard
This commit is contained in:
parent
29b4a825d1
commit
13f98cc32c
2 changed files with 15 additions and 4 deletions
|
@ -12,10 +12,11 @@ model User {
|
|||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
email String @unique
|
||||
password String
|
||||
firstName String?
|
||||
lastName String?
|
||||
email String @unique
|
||||
password String
|
||||
isAdministrator Boolean @default(false)
|
||||
firstName String?
|
||||
lastName String?
|
||||
|
||||
shares Share[]
|
||||
refreshTokens RefreshToken[]
|
||||
|
|
10
backend/src/auth/guard/isAdmin.guard.ts
Normal file
10
backend/src/auth/guard/isAdmin.guard.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { CanActivate, ExecutionContext, Injectable } from "@nestjs/common";
|
||||
import { User } from "@prisma/client";
|
||||
|
||||
@Injectable()
|
||||
export class AdministratorGuard implements CanActivate {
|
||||
canActivate(context: ExecutionContext): boolean {
|
||||
const { user }: { user: User } = context.switchToHttp().getRequest();
|
||||
return user.isAdministrator;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue