trying to make api-docs public
This commit is contained in:
parent
6cdbe702fc
commit
1210016142
@ -11,7 +11,7 @@ export class AuthGuard implements CanActivate {
|
|||||||
private readonly jwtService: JwtService,
|
private readonly jwtService: JwtService,
|
||||||
private readonly reflector: Reflector,
|
private readonly reflector: Reflector,
|
||||||
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, [
|
||||||
@ -21,6 +21,9 @@ export class AuthGuard implements CanActivate {
|
|||||||
if (isPublic) return true;
|
if (isPublic) return true;
|
||||||
|
|
||||||
const request = context.switchToHttp().getRequest<Request>();
|
const request = context.switchToHttp().getRequest<Request>();
|
||||||
|
if (request.path.startsWith('/api-docs') || request.path.startsWith('/api-json')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const authHeader = request.headers['authorization'] as string | undefined;
|
const authHeader = request.headers['authorization'] as string | undefined;
|
||||||
|
|
||||||
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
||||||
@ -30,7 +33,7 @@ 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.accessSecret'), // ✅ corrige ici
|
secret: this.configService.get<string>('jwt.accessSecret'),
|
||||||
});
|
});
|
||||||
request.user = payload;
|
request.user = payload;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user