|
|
|
@ -3,6 +3,7 @@ import { AuthGuard } from '@nestjs/passport';
|
|
|
|
|
import { lastValueFrom, Observable } from 'rxjs'; |
|
|
|
|
import { JwtStrategy } from '../../strategies/jwt.strategy'; |
|
|
|
|
import type { ExecutionContext } from '@nestjs/common'; |
|
|
|
|
import extractRolesObj from '../../utils/extractRolesObj' |
|
|
|
|
|
|
|
|
|
@Injectable() |
|
|
|
|
export class GlobalGuard extends AuthGuard(['jwt']) { |
|
|
|
@ -26,10 +27,10 @@ export class GlobalGuard extends AuthGuard(['jwt']) {
|
|
|
|
|
req.header('xc-preview') && |
|
|
|
|
['owner', 'creator'].some((role) => req.user.roles?.[role]) |
|
|
|
|
) { |
|
|
|
|
return this.authenticate({ |
|
|
|
|
return this.authenticate(req,{ |
|
|
|
|
...req.user, |
|
|
|
|
isAuthorized: true, |
|
|
|
|
roles: req.header('xc-preview'), |
|
|
|
|
roles: extractRolesObj(req.header('xc-preview')), |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -44,7 +45,7 @@ export class GlobalGuard extends AuthGuard(['jwt']) {
|
|
|
|
|
} catch {} |
|
|
|
|
|
|
|
|
|
if (canActivate) { |
|
|
|
|
return this.authenticate({ |
|
|
|
|
return this.authenticate(req,{ |
|
|
|
|
...req.user, |
|
|
|
|
isAuthorized: true, |
|
|
|
|
roles: req.user.roles === 'owner' ? 'owner,creator' : req.user.roles, |
|
|
|
@ -58,7 +59,7 @@ export class GlobalGuard extends AuthGuard(['jwt']) {
|
|
|
|
|
} catch {} |
|
|
|
|
|
|
|
|
|
if (canActivate) { |
|
|
|
|
return this.authenticate({ |
|
|
|
|
return this.authenticate(req,{ |
|
|
|
|
...req.user, |
|
|
|
|
isAuthorized: true, |
|
|
|
|
isPublicBase: true, |
|
|
|
@ -78,8 +79,8 @@ export class GlobalGuard extends AuthGuard(['jwt']) {
|
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
): Promise<any> { |
|
|
|
|
const u = this.jwtStrategy.validate(req, user); |
|
|
|
|
req.user = user; |
|
|
|
|
const u = await this.jwtStrategy.validate(req, user); |
|
|
|
|
req.user = u; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|