-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change controller's decorators structure Add public decorator and override behavior for both auth and is-reef-admin decorators Add override-level-access to override the default decorator access for some endpoints
- Loading branch information
1 parent
28deadb
commit b210757
Showing
11 changed files
with
77 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Injectable, ExecutionContext } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { Reflector } from '@nestjs/core'; | ||
import { of } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class FirebaseAuthGuard extends AuthGuard('custom') {} | ||
export class FirebaseAuthGuard extends AuthGuard('custom') { | ||
constructor(private reflector: Reflector) { | ||
super(); | ||
} | ||
|
||
canActivate(context: ExecutionContext) { | ||
const isPublic = this.reflector.get<boolean>( | ||
'isPublic', | ||
context.getHandler(), | ||
); | ||
|
||
if (isPublic) { | ||
return of(true); | ||
} | ||
|
||
return super.canActivate(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { applyDecorators, SetMetadata } from '@nestjs/common'; | ||
import { AdminLevel } from '../users/users.entity'; | ||
|
||
export const OverrideLevelAccess = (...levels: AdminLevel[]) => { | ||
return applyDecorators(SetMetadata('levels', levels)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { applyDecorators, SetMetadata } from '@nestjs/common'; | ||
|
||
export const Public = () => { | ||
return applyDecorators(SetMetadata('isPublic', true)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters