-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from conceptadev/feature/global-guards
feat(authentication): add global guard pattern and supporting setting…
- Loading branch information
Showing
36 changed files
with
346 additions
and
81 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
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,8 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { AuthGuard } from '@concepta/nestjs-authentication'; | ||
import { AUTH_GITHUB_STRATEGY_NAME } from './auth-github.constants'; | ||
|
||
@Injectable() | ||
export class AuthGithubGuard extends AuthGuard(AUTH_GITHUB_STRATEGY_NAME, { | ||
canDisable: false, | ||
}) {} |
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,3 +1,7 @@ | ||
export * from './auth-github.module'; | ||
export * from './auth-github.controller'; | ||
export * from './dto/auth-github-login.dto'; | ||
export { | ||
AuthGithubGuard, | ||
AuthGithubGuard as GithubAuthGuard, | ||
} from './auth-github.guard'; |
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
4 changes: 2 additions & 2 deletions
4
packages/nestjs-auth-jwt/src/__fixtures__/user/user.controller.fixture.ts
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,22 @@ | ||
import { AuthGuard } from '@concepta/nestjs-authentication'; | ||
import { ReferenceIdInterface } from '@concepta/ts-core'; | ||
import { Injectable, UnauthorizedException } from '@nestjs/common'; | ||
|
||
import { AUTH_JWT_STRATEGY_NAME } from './auth-jwt.constants'; | ||
|
||
@Injectable() | ||
export class AuthJwtGuard extends AuthGuard(AUTH_JWT_STRATEGY_NAME, { | ||
canDisable: true, | ||
}) { | ||
handleRequest<T = ReferenceIdInterface>( | ||
err: Error | undefined, | ||
user: T, | ||
info?: Error, | ||
) { | ||
// You can throw an exception based on either "info" or "err" arguments | ||
if (err || !user) { | ||
throw new UnauthorizedException(null, { cause: err ?? info }); | ||
} | ||
return user; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,3 +1,3 @@ | ||
export * from './auth-jwt.module'; | ||
export * from './auth-jwt.strategy'; | ||
export * from './decorator/auth-jwt.guard'; | ||
export { AuthJwtGuard, AuthJwtGuard as JwtAuthGuard } from './auth-jwt.guard'; |
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
Oops, something went wrong.