Browse Source

chore: lint

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5572/head
Pranav C 2 years ago
parent
commit
70fab17f9c
  1. 42
      packages/nocodb-nest/src/strategies/authtoken.strategy/authtoken.strategy.ts

42
packages/nocodb-nest/src/strategies/authtoken.strategy/authtoken.strategy.ts

@ -1,47 +1,45 @@
import { Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { Strategy } from 'passport-custom'
import { ApiToken, ProjectUser, User } from '../../models'
import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-custom';
import { ApiToken, ProjectUser, User } from '../../models';
@Injectable()
export class AuthTokenStrategy extends PassportStrategy(Strategy, 'authtoken') {
// eslint-disable-next-line @typescript-eslint/ban-types
async validate(req: any, callback: Function) {
try {
let user
let user;
if (req.headers['xc-token']) {
const apiToken = await ApiToken.getByToken(
req.headers['xc-token'],
)
const apiToken = await ApiToken.getByToken(req.headers['xc-token']);
if (!apiToken) {
return callback({ msg: 'Invalid token' })
return callback({ msg: 'Invalid token' });
}
user = {}
user = {};
if (!apiToken.fk_user_id) {
user.roles = 'editor'
return callback(null, user)
user.roles = 'editor';
return callback(null, user);
}
const dbUser: Record<string, any> = await User.get(apiToken.fk_user_id)
const dbUser: Record<string, any> = await User.get(apiToken.fk_user_id);
if (!dbUser) {
return callback({ msg: 'User not found' })
return callback({ msg: 'User not found' });
}
dbUser.is_api_token = true
dbUser.is_api_token = true;
if (req['ncProjectId']) {
const projectUser = await ProjectUser.get(
req['ncProjectId'],
dbUser.id,
)
user.roles = projectUser?.roles || dbUser.roles
user.roles = user.roles === 'owner' ? 'owner,creator' : user.roles
return callback(null, user)
);
user.roles = projectUser?.roles || dbUser.roles;
user.roles = user.roles === 'owner' ? 'owner,creator' : user.roles;
return callback(null, user);
}
}
return callback(null, user)
return callback(null, user);
} catch (error) {
callback(error)
callback(error);
}
}
}

Loading…
Cancel
Save