Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
feat: finish basic login and register
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Feb 1, 2020
1 parent 7452783 commit d3d28cd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/guard/gqlAuth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@ import { Injectable, ExecutionContext, CanActivate } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { GqlExecutionContext } from '@nestjs/graphql'
import { AuthenticationError } from 'apollo-server-express'
import { ConfigService } from '../config/config.service'

@Injectable()
export class GqlAuthGuard extends AuthGuard('jwt') implements CanActivate {
private isEnvTest: boolean

constructor(configService: ConfigService) {
super()
this.isEnvTest = configService.isEnvTest
}

public async canActivate(context: ExecutionContext): Promise<boolean> {
// 测试环境下跳过 token 校验
if (this.isEnvTest) {
return true
}

try {
return (await super.canActivate(context)) as boolean
} catch (e) {
Expand Down

0 comments on commit d3d28cd

Please sign in to comment.