Ajout d'un endpoint pour modifier son mot de passe
This commit is contained in:
@ -16,7 +16,7 @@ export const JWT_SECRET = env.JWT_SECRET
|
||||
PassportModule,
|
||||
JwtModule.register({
|
||||
secret: JWT_SECRET,
|
||||
signOptions: { expiresIn: '5m' },
|
||||
signOptions: { expiresIn: '12h' },
|
||||
}),
|
||||
UsersModule,
|
||||
],
|
||||
|
@ -13,9 +13,7 @@ export class AuthService {
|
||||
if (!user) {
|
||||
throw new NotFoundException(`Aucun⋅e utilisateur⋅rice avec pour nom ${name}`)
|
||||
}
|
||||
|
||||
const isPasswordValid = await bcrypt.compare(password, user.password)
|
||||
|
||||
if (!isPasswordValid) {
|
||||
throw new UnauthorizedException('Mot de passe incorrect')
|
||||
}
|
||||
@ -24,4 +22,4 @@ export class AuthService {
|
||||
accessToken: this.jwtService.sign({ userId: user.id }),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ApiProperty } from '@nestjs/swagger'
|
||||
import { IsNotEmpty, IsString, MinLength } from 'class-validator'
|
||||
import { IsNotEmpty, IsString } from 'class-validator'
|
||||
|
||||
export class LoginDto {
|
||||
@IsString()
|
||||
|
@ -3,6 +3,7 @@ import { PassportStrategy } from '@nestjs/passport'
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt'
|
||||
import { JWT_SECRET } from './auth.module'
|
||||
import { UsersService } from 'src/users/users.service'
|
||||
import { User } from '@prisma/client'
|
||||
|
||||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
||||
@ -13,7 +14,7 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
||||
})
|
||||
}
|
||||
|
||||
async validate(payload: { userId: number }) {
|
||||
async validate(payload: { userId: number }): Promise<User> {
|
||||
const user = await this.usersService.findOne(payload.userId)
|
||||
if (!user) {
|
||||
throw new UnauthorizedException()
|
||||
|
Reference in New Issue
Block a user