create-forgeon 0.1.36 → 0.1.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modules/executor.test.mjs +7 -0
- package/templates/module-presets/jwt-auth/packages/auth-api/src/auth.controller.ts +1 -1
- package/templates/module-presets/jwt-auth/packages/auth-api/src/auth.service.ts +24 -4
- package/templates/module-presets/jwt-auth/packages/auth-api/src/dto/login.dto.ts +1 -1
- package/templates/module-presets/jwt-auth/packages/auth-api/src/dto/refresh.dto.ts +1 -1
package/package.json
CHANGED
|
@@ -94,6 +94,13 @@ function assertJwtAuthWiring(projectRoot, withPrismaStore) {
|
|
|
94
94
|
|
|
95
95
|
const readme = fs.readFileSync(path.join(projectRoot, 'README.md'), 'utf8');
|
|
96
96
|
assert.match(readme, /## JWT Auth Module/);
|
|
97
|
+
|
|
98
|
+
const authServiceSource = fs.readFileSync(
|
|
99
|
+
path.join(projectRoot, 'packages', 'auth-api', 'src', 'auth.service.ts'),
|
|
100
|
+
'utf8',
|
|
101
|
+
);
|
|
102
|
+
assert.match(authServiceSource, /import type \{/);
|
|
103
|
+
assert.doesNotMatch(authServiceSource, /import\s*\{\s*AUTH_ERROR_CODES/);
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
function stripDbPrismaArtifacts(projectRoot) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
AuthErrorCode,
|
|
3
3
|
AuthUser,
|
|
4
4
|
LoginResponse,
|
|
5
5
|
RefreshResponse,
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from '@forgeon/auth-contracts';
|
|
8
8
|
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
|
|
9
9
|
import { JwtService } from '@nestjs/jwt';
|
|
10
|
+
import type { JwtSignOptions } from '@nestjs/jwt';
|
|
10
11
|
import { compare, hash } from 'bcryptjs';
|
|
11
12
|
import {
|
|
12
13
|
AUTH_REFRESH_TOKEN_STORE,
|
|
@@ -16,6 +17,17 @@ import { AuthConfigService } from './auth-config.service';
|
|
|
16
17
|
import { LoginDto, RefreshDto } from './dto';
|
|
17
18
|
import { AuthJwtPayload } from './auth.types';
|
|
18
19
|
|
|
20
|
+
type JwtExpiresIn = NonNullable<JwtSignOptions['expiresIn']>;
|
|
21
|
+
|
|
22
|
+
const AUTH_ERROR_CODES: Record<
|
|
23
|
+
'invalidCredentials' | 'tokenExpired' | 'refreshInvalid',
|
|
24
|
+
AuthErrorCode
|
|
25
|
+
> = {
|
|
26
|
+
invalidCredentials: 'AUTH_INVALID_CREDENTIALS',
|
|
27
|
+
tokenExpired: 'AUTH_TOKEN_EXPIRED',
|
|
28
|
+
refreshInvalid: 'AUTH_REFRESH_INVALID',
|
|
29
|
+
};
|
|
30
|
+
|
|
19
31
|
@Injectable()
|
|
20
32
|
export class AuthService {
|
|
21
33
|
constructor(
|
|
@@ -123,11 +135,11 @@ export class AuthService {
|
|
|
123
135
|
const [accessToken, refreshToken] = await Promise.all([
|
|
124
136
|
this.jwtService.signAsync(payload, {
|
|
125
137
|
secret: this.configService.accessSecret,
|
|
126
|
-
expiresIn: this.configService.accessExpiresIn,
|
|
138
|
+
expiresIn: this.toJwtExpiresIn(this.configService.accessExpiresIn),
|
|
127
139
|
}),
|
|
128
140
|
this.jwtService.signAsync(payload, {
|
|
129
141
|
secret: this.configService.refreshSecret,
|
|
130
|
-
expiresIn: this.configService.refreshExpiresIn,
|
|
142
|
+
expiresIn: this.toJwtExpiresIn(this.configService.refreshExpiresIn),
|
|
131
143
|
}),
|
|
132
144
|
]);
|
|
133
145
|
|
|
@@ -152,4 +164,12 @@ export class AuthService {
|
|
|
152
164
|
roles: Array.isArray(payload.roles) ? payload.roles : ['user'],
|
|
153
165
|
};
|
|
154
166
|
}
|
|
167
|
+
|
|
168
|
+
private toJwtExpiresIn(value: string): JwtExpiresIn {
|
|
169
|
+
const trimmed = value.trim();
|
|
170
|
+
if (/^\d+$/.test(trimmed)) {
|
|
171
|
+
return Number(trimmed);
|
|
172
|
+
}
|
|
173
|
+
return trimmed as JwtExpiresIn;
|
|
174
|
+
}
|
|
155
175
|
}
|