463ce43442
closes https://github.com/twentyhq/core-team-issues/issues/2180 https://github.com/user-attachments/assets/a898455d-eb1c-4d22-b585-785e98fc38a7
26 lines
758 B
TypeScript
26 lines
758 B
TypeScript
import { type CanActivate, Injectable } from '@nestjs/common';
|
|
|
|
import { NodeEnvironment } from 'src/engine/core-modules/twenty-config/interfaces/node-environment.interface';
|
|
|
|
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
|
|
|
@Injectable()
|
|
export class DevelopmentGuard implements CanActivate {
|
|
constructor(private readonly twentyConfigService: TwentyConfigService) {}
|
|
|
|
canActivate(): boolean {
|
|
const nodeEnv = this.twentyConfigService.get('NODE_ENV');
|
|
|
|
if (
|
|
nodeEnv !== NodeEnvironment.DEVELOPMENT &&
|
|
nodeEnv !== NodeEnvironment.TEST
|
|
) {
|
|
throw new Error(
|
|
'This endpoint is only available in development or test environments',
|
|
);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|