forked from Ynov/ptitspas-ynov-back
authguard corrected
This commit is contained in:
parent
b93f935564
commit
2ff4711bf6
@ -5,10 +5,6 @@ import { Request } from 'express';
|
|||||||
import { IS_PUBLIC_KEY } from "../decorators/public.decorator";
|
import { IS_PUBLIC_KEY } from "../decorators/public.decorator";
|
||||||
import { ConfigService } from "@nestjs/config";
|
import { ConfigService } from "@nestjs/config";
|
||||||
|
|
||||||
interface AuthenticatedRequest extends Request {
|
|
||||||
user?: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
constructor(
|
constructor(
|
||||||
@ -17,7 +13,6 @@ export class AuthGuard implements CanActivate {
|
|||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|
||||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
||||||
context.getHandler(),
|
context.getHandler(),
|
||||||
@ -34,13 +29,13 @@ export class AuthGuard implements CanActivate {
|
|||||||
|
|
||||||
const token = authHeader.split(' ')[1];
|
const token = authHeader.split(' ')[1];
|
||||||
try {
|
try {
|
||||||
const payload = await this.jwtService.verifyAsync(token,
|
const payload = await this.jwtService.verifyAsync(token, {
|
||||||
{ secret: this.configService.get<string>('jwt.secret') },
|
secret: this.configService.get<string>('jwt.accessSecret'), // ✅ corrige ici
|
||||||
);
|
});
|
||||||
request.user = payload;
|
request.user = payload;
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new UnauthorizedException('Token invalide ou expire');
|
throw new UnauthorizedException('Token invalide ou expiré');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user