NestJS - Guards
Identify the error in this JWT guard snippet that causes it to always allow access even with invalid tokens:
async canActivate(context: ExecutionContext) {
const request = context.switchToHttp().getRequest();
const token = request.headers['authorization']?.split(' ')[1];
if (!token) return false;
try {
const payload = await this.jwtService.verifyAsync(token);
request.user = payload;
} catch {
return true;
}
return true;
}