This repository has been archived by the owner on Jul 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Graphql-Auth-Guard and CurrentUser decorator
Ditched custom auth guard instead of the improved GraphqlAuthGuard. You now can get the user who logged in by using @currentuser() user: any as function parameter
- Loading branch information
Showing
13 changed files
with
89 additions
and
65 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 |
---|---|---|
|
@@ -23,7 +23,7 @@ import { ExamResultModule } from './modules/examResult/examResult.module'; | |
{ | ||
autoSchemaFile: 'schema.gpl', | ||
installSubscriptionHandlers: true, | ||
context: ({req}) => {return {request: req};} | ||
context: ({req}) => ({req}) | ||
}), | ||
MongooseModule.forRoot(`mongodb://admin:admin%[email protected]:27017/examadmin?authSource=admin&compressors=zlib&readPreference=primary&gssapiServiceName=mongodb&appname=MongoDB%20Compass%20Community&ssl=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
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,4 @@ | ||
// user.decorator.ts | ||
import { createParamDecorator } from '@nestjs/common'; | ||
|
||
export const User = createParamDecorator((data, [root, args, ctx, info]) => ctx.req.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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { GqlExecutionContext } from '@nestjs/graphql'; | ||
import { Observable } from 'rxjs'; | ||
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host'; | ||
|
||
@Injectable() | ||
export class GqlAuthGuard extends AuthGuard('jwt') { | ||
getRequest(context: ExecutionContext) { | ||
export class GraphqlAuthGuard extends AuthGuard('jwt') { | ||
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> { | ||
const ctx = GqlExecutionContext.create(context); | ||
return ctx.getContext().req; | ||
const { req } = ctx.getContext(); | ||
return super.canActivate(new ExecutionContextHost([req])); | ||
} | ||
} |
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