I'm a junior full-stack developer from Alexandria, Egypt. This is another post about FaceMark, my face-recognition attendance system (a NestJS API plus a Python AI service). This one covers authorization: how the API decides that a student can see their own attendance but nobody else's, and that only staff and admins can pull class-wide records.
FaceMark has three roles, defined as a plain enum:
// src/common/enums/role.enum.ts export enum Role { ADMIN = 'admin' , STAFF = 'staff' , STUDENT = 'student' , }
Enter fullscreen mode
Exit fullscreen mode
The system is three small pieces: a JWT guard that answers "who are you", a decorator that answers "who is allowed here", and a roles guard that compares the two.
The JWT guard
// src/auth/guards/jwt-auth.guard.ts @Injectable ( ) export class JwtAuthGuard extends AuthGuard ( 'jwt' ) { }
Enter fullscreen mode
Exit fullscreen mode
That's the whole file. It extends Passport's JWT AuthGuard: no valid token, no request.…