Browse Source

refactor: allow only one token per user

pull/6594/head
Pranav C 1 year ago
parent
commit
26de94bfc1
  1. 8
      packages/nocodb/src/helpers/catchError.ts
  2. 2
      packages/nocodb/src/services/api-tokens.service.ts

8
packages/nocodb/src/helpers/catchError.ts

@ -415,6 +415,8 @@ export default function (
return res.status(400).json({ msg: e.message, errors: e.errors });
} else if (e instanceof UnprocessableEntity) {
return res.status(422).json({ msg: e.message });
} else if (e instanceof NotAllowed) {
return res.status(405).json({ msg: e.message });
}
next(e);
}
@ -423,6 +425,8 @@ export default function (
export class BadRequest extends Error {}
export class NotAllowed extends Error {}
export class Unauthorized extends Error {}
export class Forbidden extends Error {}
@ -476,4 +480,8 @@ export class NcError {
static unprocessableEntity(message = 'Unprocessable entity') {
throw new UnprocessableEntity(message);
}
static notAllowed(message = 'Not allowed') {
throw new NotAllowed(message);
}
}

2
packages/nocodb/src/services/api-tokens.service.ts

@ -9,7 +9,7 @@ import { ApiToken } from '~/models';
@Injectable()
export class ApiTokensService {
constructor(private readonly appHooksService: AppHooksService) {}
constructor(protected readonly appHooksService: AppHooksService) {}
async apiTokenList(param: { userId: string }) {
return await ApiToken.list(param.userId);

Loading…
Cancel
Save