add auth docs, add eslint import/order

This commit is contained in:
andres
2023-07-16 19:44:58 +02:00
parent 0f3e89900a
commit aa7ece41a9
74 changed files with 1152 additions and 164 deletions

View File

@@ -1,6 +1,7 @@
import { Inject, Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { ExtractJwt, Strategy } from 'passport-jwt'
import { AppSettings } from '../../../settings/app-settings'
type JwtPayload = {

View File

@@ -1,15 +1,18 @@
import { Inject, Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { Strategy } from 'passport-jwt'
import { UsersService } from '../../users/services/users.service'
import { AppSettings } from '../../../settings/app-settings'
import { Request } from 'express'
import { Strategy } from 'passport-jwt'
import { AppSettings } from '../../../settings/app-settings'
import { UsersService } from '../../users/services/users.service'
const cookieExtractor = function (req: Request) {
let token = null
if (req && req.cookies) {
token = req.cookies['refreshToken']
}
return token
}

View File

@@ -1,10 +1,11 @@
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { Request as RequestType } from 'express'
import { ExtractJwt, Strategy } from 'passport-jwt'
import { AuthService } from '../auth.service'
import { AppSettings } from '../../../settings/app-settings'
import { UsersService } from '../../users/services/users.service'
import { Request as RequestType } from 'express'
import { AuthService } from '../auth.service'
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
@@ -25,9 +26,11 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
async validate(payload: any) {
const user = await this.userService.getUserById(payload.userId)
if (!user) {
throw new UnauthorizedException()
}
return user
}
@@ -35,6 +38,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
if (req.cookies && 'accessToken' in req.cookies && req.cookies.accessToken.length > 0) {
return req.cookies.accessToken
}
return null
}
}

View File

@@ -1,6 +1,7 @@
import { Injectable, UnauthorizedException } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { Strategy } from 'passport-local'
import { AuthService } from '../auth.service'
@Injectable()
@@ -13,9 +14,11 @@ export class LocalStrategy extends PassportStrategy(Strategy) {
async validate(email: string, password: string): Promise<any> {
const newCredentials = await this.authService.checkCredentials(email, password)
if (newCredentials.resultCode === 1) {
throw new UnauthorizedException('Invalid credentials')
}
return newCredentials
}
}