* wip: refacto and start creating custom resolver * feat: findMany & findUnique of a custom entity * feat: wip pagination * feat: initial metadata migration * feat: universal findAll with pagination * fix: clean small stuff in pagination * fix: test * fix: miss file * feat: rename custom into universal * feat: create metadata schema in default database * Multi-tenant db schemas POC fix tests and use query builders remove synchronize restore updatedAt remove unnecessary import use queryRunner fix camelcase add migrations for standard objects Multi-tenant db schemas POC fix tests and use query builders remove synchronize restore updatedAt remove unnecessary import use queryRunner fix camelcase add migrations for standard objects poc: conditional schema at runtime wip: try to create resolver in Nest.JS context fix * feat: wip add pg_graphql * feat: setup pg_graphql during database init * wip: dynamic resolver * poc: dynamic resolver and query using pg_graphql * feat: pg_graphql use ARG in Dockerfile * feat: clean findMany & findOne dynamic resolver * feat: get correct schema based on access token * fix: remove old file * fix: tests * fix: better comment * fix: e2e test not working, error format change due to yoga * remove typeorm entity generation + fix jwt + fix search_path + remove anon * fix conflict --------- Co-authored-by: Charles Bochet <charles@twenty.com> Co-authored-by: corentin <corentin@twenty.com>
41 lines
811 B
TypeScript
41 lines
811 B
TypeScript
import {
|
|
ExecutionContext,
|
|
Injectable,
|
|
UnauthorizedException,
|
|
} from '@nestjs/common';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
import { JsonWebTokenError } from 'jsonwebtoken';
|
|
|
|
import { assert } from 'src/utils/assert';
|
|
import { getRequest } from 'src/utils/extract-request';
|
|
|
|
@Injectable()
|
|
export class JwtAuthGuard extends AuthGuard(['jwt']) {
|
|
constructor() {
|
|
super();
|
|
}
|
|
|
|
getRequest(context: ExecutionContext) {
|
|
return getRequest(context);
|
|
}
|
|
|
|
handleRequest(err: any, user: any, info: any) {
|
|
assert(user, '', UnauthorizedException);
|
|
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
|
|
if (info && info instanceof Error) {
|
|
if (info instanceof JsonWebTokenError) {
|
|
info = String(info);
|
|
}
|
|
|
|
throw new UnauthorizedException(info);
|
|
}
|
|
|
|
return user;
|
|
}
|
|
}
|