From aa80db1bb1ee1d71d20d0cf1ece34f23fca7545a Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Tue, 3 Nov 2020 18:05:10 +0530 Subject: [PATCH] :recycle: Use constant for login token sub --- http/users/get.http | 6 ++++++ src/modules/auth/auth.service.ts | 3 ++- src/modules/tokens/tokens.constants.ts | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 http/users/get.http diff --git a/http/users/get.http b/http/users/get.http new file mode 100644 index 000000000..a17b08f34 --- /dev/null +++ b/http/users/get.http @@ -0,0 +1,6 @@ +@baseUrl = http://localhost:3000 +@userId = 1 + +GET {{baseUrl}}/users/{{userId}} +content-type: application/json +Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMSIsInNjb3BlcyI6WyJ1c2VyLTE6KiJdLCJpYXQiOjE2MDQ0MDY1NjksImV4cCI6MTYwNDQxMDE2OX0.AMBGQtM4pfdyJSopI9jnV_5bZbHTkgwuOrC1ttyYvwk diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts index e53f8ac72..65baa6989 100644 --- a/src/modules/auth/auth.service.ts +++ b/src/modules/auth/auth.service.ts @@ -28,6 +28,7 @@ import { MULTI_FACTOR_TOKEN, PASSWORD_RESET_TOKEN, EMAIL_MFA_TOKEN, + LOGIN_ACCESS_TOKEN, } from '../tokens/tokens.constants'; import { TokensService } from '../tokens/tokens.service'; import { RegisterDto } from './auth.dto'; @@ -467,7 +468,7 @@ export class AuthService { private async getAccessToken(userId: number): Promise { const scopes = await this.getScopes(userId); const payload: AccessTokenClaims = { - sub: `user${userId}`, + sub: LOGIN_ACCESS_TOKEN, scopes, }; return this.jwtService.sign(payload, { diff --git a/src/modules/tokens/tokens.constants.ts b/src/modules/tokens/tokens.constants.ts index 0d337fd31..f514cbe0e 100644 --- a/src/modules/tokens/tokens.constants.ts +++ b/src/modules/tokens/tokens.constants.ts @@ -3,3 +3,4 @@ export const PASSWORD_RESET_TOKEN = 'PASSWORD_RESET_TOKEN'; export const EMAIL_VERIFY_TOKEN = 'EMAIL_VERIFY_TOKEN'; export const APPROVE_SUBNET_TOKEN = 'APPROVE_SUBNET_TOKEN'; export const EMAIL_MFA_TOKEN = 'EMAIL_MFA_TOKEN'; +export const LOGIN_ACCESS_TOKEN = 'LOGIN_ACCESS_TOKEN';