Skip to content

Commit c80e581

Browse files
committed
added uuid into jwt token
1 parent 34962d7 commit c80e581

7 files changed

Lines changed: 43 additions & 6 deletions

File tree

package-lock.json

Lines changed: 33 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"@types/supertest": "^2.0.12",
7070
"@typescript-eslint/eslint-plugin": "^5.61.0",
7171
"@typescript-eslint/parser": "^5.61.0",
72+
"uuid": "^11.0.3",
7273
"rimraf": "^5.0.1",
7374
"eslint": "^8.44.0",
7475
"eslint-config-prettier": "^8.8.0",
@@ -93,6 +94,7 @@
9394
"@nestjs/passport": "^10.0.0 || ^9.0.0 || ^8.0.0 || ^7.0.0",
9495
"@nestjs/graphql": "^12.0.0 || ^11.0.0 || ^10.0.0 || ^9.0.0 || ^8.0.0 || ^7.0.0",
9596
"@nestjs/swagger": "^7.0.0 || ^6.0.0 || ^5.0.0",
97+
"uuid": "^11.0.0 || ^10.0.0",
9698
"moment": "^2.0.0",
9799
"graphql": "^16.0.0 || ^15.0.0",
98100
"class-transformer": "^0.5.0",

src/__tests__/cases/e2e-tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export function e2eTestsSetup<T extends INestApplication>(
166166
expect(res.userData).toBeDefined()
167167
expect(res.userData.id).toBeDefined()
168168
expect(res.userData.username).toBeDefined()
169+
expect(res.userData.uuid).toBeDefined()
169170
})
170171
})
171172

src/__tests__/helpers/sample.auth.repository.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class SampleAuthRepository implements AuthRepository<string, AuthDto> {
2424
id: (Math.floor(Math.random() * 1999) + 1).toString(),
2525
username: 'sample-user@gmail.com',
2626
email: 'sample-user@gmail.com',
27+
uuid: 'sample-user-uuid',
2728
password,
2829
}))
2930
)

src/domain/entities/jwt.payload.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface IJwtPayload<T = string> {
66
exp: number
77
iss: string
88
sub: T
9+
uuid?: string
910
username?: string
1011
}
1112

@@ -14,6 +15,7 @@ export interface IJwtPayloadRawDecoded {
1415
exp: number
1516
iss: string
1617
sub: string
18+
uuid?: string
1719
username?: string
1820
}
1921

src/domain/services/__tests__/token.service.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe('TokenService', () => {
4343
expect(res?.sub).toEqual(userInfo.id)
4444
expect(res?.exp).toBeGreaterThan(0)
4545
expect(res?.iat).toBeGreaterThan(0)
46+
expect(typeof res?.uuid).toEqual('string')
4647
})
4748
)
4849
)
@@ -69,6 +70,7 @@ describe('TokenService', () => {
6970
expect(res?.sub).toEqual(userInfo.id)
7071
expect(res?.exp).toBeGreaterThan(0)
7172
expect(res?.iat).toBeGreaterThan(0)
73+
expect(typeof res?.uuid).toEqual('string')
7274
})
7375
)
7476
)

src/domain/services/token.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
IJwtPayloadRawDecoded,
1111
} from '../index'
1212
import { HashTextService } from './hash-text.service'
13+
import { v6 as uuidV6 } from 'uuid'
1314

1415
export interface IJwtTokenResponse {
1516
accessToken: string
@@ -63,6 +64,7 @@ export class TokenService {
6364
),
6465
sub: this.hashTextService.encode(userInfo.id),
6566
iss: 'self-signed',
67+
uuid: uuidV6(),
6668
}).pipe(
6769
map((payload) =>
6870
this.jwtService.sign(payload, {

0 commit comments

Comments
 (0)