Skip to content

Commit 92f60d7

Browse files
refactor(auth): rename self-host secret key to self-host token and update related logic
- Changed environment variable from `SELF_HOSTED_SECRET_KEY` to `SELF_HOSTED_TOKEN`. - Updated header keys in `SelfHostSecretGuard` and `jwt-manager` to reflect the new naming. - Adjusted error messages for missing and invalid tokens.
1 parent 4a22cb4 commit 92f60d7

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

apps/api/src/app/auth/framework/self-host-secret.guard.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import { HttpRequestHeaderKeysEnum } from '@novu/application-generic';
44
@Injectable()
55
export class SelfHostSecretGuard implements CanActivate {
66
canActivate(context: ExecutionContext): boolean {
7-
const secretKey = process.env.SELF_HOSTED_SECRET_KEY;
7+
const secretKey = process.env.SELF_HOSTED_TOKEN;
88
if (!secretKey) return true;
99

1010
const request = context.switchToHttp().getRequest();
11-
const headerKey = request.headers[HttpRequestHeaderKeysEnum.NOVU_SELF_HOSTED_SECRET_KEY.toLowerCase()];
11+
const headerKey = request.headers[HttpRequestHeaderKeysEnum.NOVU_SELF_HOSTED_TOKEN.toLowerCase()];
1212

1313
if (!headerKey) {
14-
throw new UnauthorizedException('Missing self-host secret key');
14+
throw new UnauthorizedException('Missing self-host token');
1515
}
1616

1717
if (headerKey !== secretKey) {
18-
throw new UnauthorizedException('Invalid self-host secret key');
18+
throw new UnauthorizedException('Invalid self-host token');
1919
}
2020

2121
return true;

apps/dashboard/src/config/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const ONBOARDING_DEMO_WORKFLOW_ID = 'onboarding-demo-workflow';
3232

3333
export const IS_SELF_HOSTED = import.meta.env.VITE_SELF_HOSTED;
3434

35-
export const SELF_HOSTED_SECRET_KEY = import.meta.env.VITE_SELF_HOSTED_SECRET_KEY;
35+
export const SELF_HOSTED_TOKEN = import.meta.env.VITE_SELF_HOSTED_TOKEN;
3636

3737
if (!IS_SELF_HOSTED && !CLERK_PUBLISHABLE_KEY) {
3838
throw new Error('Missing Clerk Publishable Key');

apps/dashboard/src/utils/self-hosted/jwt-manager.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { get } from '../../api/api.client';
2-
import { SELF_HOSTED_SECRET_KEY } from '../../config';
2+
import { SELF_HOSTED_TOKEN } from '../../config';
33

44
const JWT_STORAGE_KEY = 'self-hosted-jwt';
55

66
export async function refreshJwt(): Promise<string | null> {
77
try {
8-
const headers: HeadersInit = SELF_HOSTED_SECRET_KEY
9-
? { 'novu-self-hosted-secret-key': SELF_HOSTED_SECRET_KEY }
10-
: {};
8+
const headers: HeadersInit = SELF_HOSTED_TOKEN ? { 'novu-self-hosted-token': SELF_HOSTED_TOKEN } : {};
119
const result = await get<{ data: { token: string } }>('/auth/self-hosted', { headers });
1210
const token = result?.data?.token;
1311

libs/application-generic/src/http/headers.types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export enum HttpRequestHeaderKeysEnum {
1212
NOVU_USER_AGENT = 'Novu-User-Agent',
1313
BYPASS_TUNNEL_REMINDER = 'Bypass-Tunnel-Reminder',
1414
IDEMPOTENCY_KEY = 'Idempotency-Key',
15-
NOVU_SELF_HOSTED_SECRET_KEY = 'Novu-Self-Hosted-Secret-Key',
15+
NOVU_SELF_HOSTED_TOKEN = 'Novu-Self-Hosted-Token',
1616
}
1717
testHttpHeaderEnumValidity(HttpRequestHeaderKeysEnum);
1818

0 commit comments

Comments
 (0)