Browse Source

fix: preview as auth guard corrections

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
fdcbbb1bc9
  1. 13
      packages/nocodb-nest/src/guards/global/global.guard.ts
  2. 1
      packages/nocodb-nest/src/modules/tables/tables.service.ts

13
packages/nocodb-nest/src/guards/global/global.guard.ts

@ -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;
}

1
packages/nocodb-nest/src/modules/tables/tables.service.ts

@ -1,3 +1,4 @@
import { Injectable } from '@nestjs/common';
import DOMPurify from 'isomorphic-dompurify';
import {

Loading…
Cancel
Save