Skip to content

Commit

Permalink
'.'
Browse files Browse the repository at this point in the history
  • Loading branch information
ManucherKM committed Sep 21, 2023
1 parent 4a73134 commit de82980
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"arrowParens": "avoid",
"proseWrap": "always",
"endOfLine": "lf",
"organizeImportsSkipDestructiveCodeActions": false
"organizeImportsSkipDestructiveCodeActions": true
}
21 changes: 21 additions & 0 deletions src/jwt/guards/jwt-auth.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'
import { Request } from 'express'
import { Observable } from 'rxjs'
import { JwtService } from '../jwt.service'

@Injectable()
export class JwtAuthGuard implements CanActivate {
constructor(private readonly jwtService: JwtService) {}

async canActivate(context: ExecutionContext) {
const req: Request = context.switchToHttp().getRequest()
const token = req.headers.authorization.split(' ')[1]
console.log(token)
const [isValid, data] = await this.jwtService.validateToken('access', token)
if (!isValid) {
return false
}

return true
}
}
5 changes: 1 addition & 4 deletions src/jwt/jwt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ export class JwtService {
return refreshToken
}

private async validateToken(
variant: `${EVariantValidateToken}`,
token: string,
) {
async validateToken(variant: `${EVariantValidateToken}`, token: string) {
let secret = ''

if (variant === EVariantValidateToken.access) {
Expand Down

0 comments on commit de82980

Please sign in to comment.