test/e2e/rbac/guards/auth.guard.ts   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 29
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 21
mnd 2
bc 2
fnc 1
dl 0
loc 29
bpm 2
cpm 3
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A AuthGuard.canActivate 0 22 3
1
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
2
3
@Injectable()
4
export class AuthGuard implements CanActivate {
5
6
  async canActivate(
7
    context: ExecutionContext,
8
  ): Promise<boolean> {
9
    const request = context.switchToHttp().getRequest();
10
    const role = request.headers.role;
11
12
    if (role === 'admin') {
13
      request.user = {
14
        role: 'admin',
15
      };
16
      return true;
17
    }
18
19
    if (role === 'user') {
20
      request.user = {
21
        role: 'user',
22
      };
23
      return true;
24
    }
25
26
    return false;
27
  }
28
}
29