@ambushsoftworks/nestjs-auth-graphql 0.6.5 → 0.7.2
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/README.md +590 -1291
- package/dist/auth.module.d.ts +7 -3
- package/dist/auth.module.d.ts.map +1 -1
- package/dist/auth.module.js +13 -0
- package/dist/auth.module.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -1
- package/dist/constants.js.map +1 -1
- package/dist/decorators/current-realm.decorator.d.ts +2 -0
- package/dist/decorators/current-realm.decorator.d.ts.map +1 -0
- package/dist/decorators/current-realm.decorator.js +10 -0
- package/dist/decorators/current-realm.decorator.js.map +1 -0
- package/dist/dto/jwt-payload.interface.d.ts +1 -0
- package/dist/dto/jwt-payload.interface.d.ts.map +1 -1
- package/dist/guards/csrf.guard.d.ts +0 -1
- package/dist/guards/csrf.guard.d.ts.map +1 -1
- package/dist/guards/csrf.guard.js +2 -8
- package/dist/guards/csrf.guard.js.map +1 -1
- package/dist/guards/permission.guard.d.ts +0 -1
- package/dist/guards/permission.guard.d.ts.map +1 -1
- package/dist/guards/permission.guard.js +2 -8
- package/dist/guards/permission.guard.js.map +1 -1
- package/dist/guards/tenant.guard.d.ts +0 -1
- package/dist/guards/tenant.guard.d.ts.map +1 -1
- package/dist/guards/tenant.guard.js +2 -9
- package/dist/guards/tenant.guard.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/jwt-payload-factory.interface.d.ts +1 -0
- package/dist/interfaces/jwt-payload-factory.interface.d.ts.map +1 -1
- package/dist/interfaces/realm-extractor.interface.d.ts +4 -0
- package/dist/interfaces/realm-extractor.interface.d.ts.map +1 -0
- package/dist/interfaces/realm-extractor.interface.js +3 -0
- package/dist/interfaces/realm-extractor.interface.js.map +1 -0
- package/dist/interfaces/user-repository.interface.d.ts +6 -5
- package/dist/interfaces/user-repository.interface.d.ts.map +1 -1
- package/dist/middleware/realm.middleware.d.ts +8 -0
- package/dist/middleware/realm.middleware.d.ts.map +1 -0
- package/dist/middleware/realm.middleware.js +41 -0
- package/dist/middleware/realm.middleware.js.map +1 -0
- package/dist/resolvers/base-auth.resolver.d.ts +12 -3
- package/dist/resolvers/base-auth.resolver.d.ts.map +1 -1
- package/dist/resolvers/base-auth.resolver.js +63 -74
- package/dist/resolvers/base-auth.resolver.js.map +1 -1
- package/dist/resolvers/oauth.controller.d.ts +1 -1
- package/dist/resolvers/oauth.controller.d.ts.map +1 -1
- package/dist/resolvers/oauth.controller.js +10 -6
- package/dist/resolvers/oauth.controller.js.map +1 -1
- package/dist/services/auth.service.d.ts +17 -13
- package/dist/services/auth.service.d.ts.map +1 -1
- package/dist/services/auth.service.js +70 -111
- package/dist/services/auth.service.js.map +1 -1
- package/dist/services/biometric-auth.service.d.ts +0 -1
- package/dist/services/biometric-auth.service.d.ts.map +1 -1
- package/dist/services/biometric-auth.service.js +0 -6
- package/dist/services/biometric-auth.service.js.map +1 -1
- package/dist/services/brute-force-protection.service.d.ts +4 -4
- package/dist/services/brute-force-protection.service.d.ts.map +1 -1
- package/dist/services/brute-force-protection.service.js +8 -8
- package/dist/services/brute-force-protection.service.js.map +1 -1
- package/dist/services/default-jwt-payload-factory.d.ts +1 -0
- package/dist/services/default-jwt-payload-factory.d.ts.map +1 -1
- package/dist/services/default-jwt-payload-factory.js +5 -1
- package/dist/services/default-jwt-payload-factory.js.map +1 -1
- package/dist/services/oauth-linking-token.service.d.ts.map +1 -1
- package/dist/services/oauth-linking-token.service.js +3 -8
- package/dist/services/oauth-linking-token.service.js.map +1 -1
- package/dist/services/verification.service.d.ts +9 -7
- package/dist/services/verification.service.d.ts.map +1 -1
- package/dist/services/verification.service.js +36 -131
- package/dist/services/verification.service.js.map +1 -1
- package/dist/strategies/api-key.strategy.d.ts +1 -1
- package/dist/strategies/api-key.strategy.d.ts.map +1 -1
- package/dist/strategies/api-key.strategy.js +3 -6
- package/dist/strategies/api-key.strategy.js.map +1 -1
- package/dist/strategies/jwt.strategy.d.ts +3 -1
- package/dist/strategies/jwt.strategy.d.ts.map +1 -1
- package/dist/strategies/jwt.strategy.js +10 -1
- package/dist/strategies/jwt.strategy.js.map +1 -1
- package/dist/utils/execution-context.d.ts +3 -0
- package/dist/utils/execution-context.d.ts.map +1 -0
- package/dist/utils/execution-context.js +12 -0
- package/dist/utils/execution-context.js.map +1 -0
- package/dist/utils/request-helpers.d.ts +2 -0
- package/dist/utils/request-helpers.d.ts.map +1 -0
- package/dist/utils/request-helpers.js +9 -0
- package/dist/utils/request-helpers.js.map +1 -0
- package/package.json +1 -1
|
@@ -13,8 +13,10 @@ import { IAuthLogger } from '../interfaces/auth-logger.interface';
|
|
|
13
13
|
import { IRateLimiter } from '../interfaces/rate-limiter.interface';
|
|
14
14
|
import { IJwtPayloadFactory } from '../interfaces/jwt-payload-factory.interface';
|
|
15
15
|
import { JwtPayload } from '../dto/jwt-payload.interface';
|
|
16
|
+
import { IPhoneVerificationUser } from '../dto/phone-verification-response.dto';
|
|
16
17
|
import { IAuthUser } from '../interfaces/auth-user.interface';
|
|
17
18
|
import { SocialProvider } from '../utils/provider-helpers';
|
|
19
|
+
import type { AuthModuleOptions } from '../auth.module';
|
|
18
20
|
export declare class AuthService {
|
|
19
21
|
private userRepository;
|
|
20
22
|
private refreshTokenRepository;
|
|
@@ -35,18 +37,18 @@ export declare class AuthService {
|
|
|
35
37
|
private readonly authModuleOptions;
|
|
36
38
|
private readonly jwtPayloadFactory;
|
|
37
39
|
private static readonly DUMMY_HASH;
|
|
38
|
-
constructor(userRepository: IUserRepository<IAuthUser>, refreshTokenRepository: IRefreshTokenRepository, jwtService: JwtService, refreshTokenService: RefreshTokenService, bruteForceProtection: BruteForceProtectionService, verificationService: VerificationService, oauthLinkingTokenService: OAuthLinkingTokenService, facebookStrategy: FacebookStrategy, securityLogger: IAuthLogger, lifecycleHooks: IAuthLifecycleHooks<IAuthUser>, emailService: IEmailService, smsService: ISmsService, authModuleOptions:
|
|
39
|
-
signup(email: string, password: string): Promise<{
|
|
40
|
+
constructor(userRepository: IUserRepository<IAuthUser>, refreshTokenRepository: IRefreshTokenRepository, jwtService: JwtService, refreshTokenService: RefreshTokenService, bruteForceProtection: BruteForceProtectionService, verificationService: VerificationService, oauthLinkingTokenService: OAuthLinkingTokenService, facebookStrategy: FacebookStrategy, securityLogger: IAuthLogger, lifecycleHooks: IAuthLifecycleHooks<IAuthUser>, emailService: IEmailService, smsService: ISmsService, authModuleOptions: AuthModuleOptions, rateLimiter: IRateLimiter, jwtPayloadFactory?: IJwtPayloadFactory);
|
|
41
|
+
signup(email: string, password: string, realm?: string): Promise<{
|
|
40
42
|
accessToken: string;
|
|
41
43
|
refreshToken: string;
|
|
42
44
|
user: IAuthUser;
|
|
43
45
|
}>;
|
|
44
|
-
login(email: string, password: string, ipAddress?: string): Promise<{
|
|
46
|
+
login(email: string, password: string, ipAddress?: string, realm?: string): Promise<{
|
|
45
47
|
accessToken: string;
|
|
46
48
|
refreshToken: string;
|
|
47
49
|
user: IAuthUser;
|
|
48
50
|
}>;
|
|
49
|
-
refreshToken(refreshToken: string, ipAddress?: string): Promise<{
|
|
51
|
+
refreshToken(refreshToken: string, ipAddress?: string, realm?: string): Promise<{
|
|
50
52
|
accessToken: string;
|
|
51
53
|
refreshToken: string;
|
|
52
54
|
user: IAuthUser;
|
|
@@ -58,15 +60,15 @@ export declare class AuthService {
|
|
|
58
60
|
success: boolean;
|
|
59
61
|
message: string;
|
|
60
62
|
}>;
|
|
61
|
-
verifyEmail(email: string, code: string): Promise<{
|
|
63
|
+
verifyEmail(email: string, code: string, realm?: string): Promise<{
|
|
62
64
|
success: boolean;
|
|
63
65
|
message: string;
|
|
64
66
|
}>;
|
|
65
|
-
resendVerificationEmail(email: string): Promise<{
|
|
67
|
+
resendVerificationEmail(email: string, realm?: string): Promise<{
|
|
66
68
|
success: boolean;
|
|
67
69
|
message: string;
|
|
68
70
|
}>;
|
|
69
|
-
sendPhoneVerification(userId: string, phoneNumber: string, countryCode?: string): Promise<{
|
|
71
|
+
sendPhoneVerification(userId: string, phoneNumber: string, countryCode?: string, realm?: string): Promise<{
|
|
70
72
|
success: boolean;
|
|
71
73
|
message: string;
|
|
72
74
|
phoneNumber?: string;
|
|
@@ -75,7 +77,7 @@ export declare class AuthService {
|
|
|
75
77
|
verifyPhone(userId: string, phoneNumber: string, code: string): Promise<{
|
|
76
78
|
success: boolean;
|
|
77
79
|
message: string;
|
|
78
|
-
user?:
|
|
80
|
+
user?: IPhoneVerificationUser;
|
|
79
81
|
}>;
|
|
80
82
|
resendPhoneVerification(userId: string, phoneNumber: string): Promise<{
|
|
81
83
|
success: boolean;
|
|
@@ -85,7 +87,7 @@ export declare class AuthService {
|
|
|
85
87
|
removePhoneNumber(userId: string): Promise<{
|
|
86
88
|
success: boolean;
|
|
87
89
|
message: string;
|
|
88
|
-
user?:
|
|
90
|
+
user?: Partial<IAuthUser>;
|
|
89
91
|
}>;
|
|
90
92
|
handleSocialLogin(provider: 'google' | 'facebook' | 'apple', profile: {
|
|
91
93
|
googleId?: string;
|
|
@@ -95,12 +97,12 @@ export declare class AuthService {
|
|
|
95
97
|
emailVerified: boolean;
|
|
96
98
|
firstName?: string;
|
|
97
99
|
lastName?: string;
|
|
98
|
-
}, _ipAddress?: string): Promise<{
|
|
100
|
+
}, _ipAddress?: string, realm?: string): Promise<{
|
|
99
101
|
accessToken: string;
|
|
100
102
|
refreshToken: string;
|
|
101
103
|
user: IAuthUser;
|
|
102
104
|
}>;
|
|
103
|
-
completeFacebookSignUp(fallbackToken: string, email: string, accessToken: string): Promise<{
|
|
105
|
+
completeFacebookSignUp(fallbackToken: string, email: string, accessToken: string, realm?: string): Promise<{
|
|
104
106
|
accessToken: string;
|
|
105
107
|
refreshToken: string;
|
|
106
108
|
user: IAuthUser;
|
|
@@ -111,12 +113,12 @@ export declare class AuthService {
|
|
|
111
113
|
user: IAuthUser;
|
|
112
114
|
alreadyUnlinked: boolean;
|
|
113
115
|
}>;
|
|
114
|
-
requestPasswordReset(email: string, ipAddress?: string): Promise<{
|
|
116
|
+
requestPasswordReset(email: string, ipAddress?: string, realm?: string): Promise<{
|
|
115
117
|
success: boolean;
|
|
116
118
|
message: string;
|
|
117
119
|
retryAfterSeconds?: number;
|
|
118
120
|
}>;
|
|
119
|
-
resetPassword(email: string, code: string, newPassword: string, ipAddress?: string): Promise<{
|
|
121
|
+
resetPassword(email: string, code: string, newPassword: string, ipAddress?: string, realm?: string): Promise<{
|
|
120
122
|
success: boolean;
|
|
121
123
|
message: string;
|
|
122
124
|
user: IAuthUser;
|
|
@@ -128,6 +130,8 @@ export declare class AuthService {
|
|
|
128
130
|
clearAuthCookies(res: {
|
|
129
131
|
clearCookie: (name: string, options: Record<string, unknown>) => void;
|
|
130
132
|
}): void;
|
|
133
|
+
maskPhoneNumber(phone: string): string;
|
|
131
134
|
private generateToken;
|
|
135
|
+
private generateTokenPairAndStore;
|
|
132
136
|
}
|
|
133
137
|
//# sourceMappingURL=auth.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,g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|
85
85
|
this.jwtPayloadFactory = jwtPayloadFactory || new default_jwt_payload_factory_1.DefaultJwtPayloadFactory();
|
|
86
86
|
this.passwordValidationService = new password_validation_service_1.PasswordValidationService(authModuleOptions?.passwordPolicy);
|
|
87
87
|
}
|
|
88
|
-
async signup(email, password) {
|
|
88
|
+
async signup(email, password, realm) {
|
|
89
89
|
const passwordHash = await bcrypt.hash(password, this.bcryptRounds);
|
|
90
90
|
let user;
|
|
91
91
|
try {
|
|
@@ -93,6 +93,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
93
93
|
email,
|
|
94
94
|
passwordHash,
|
|
95
95
|
authProvider: auth_user_interface_1.AuthProvider.EMAIL,
|
|
96
|
+
realm,
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
catch (error) {
|
|
@@ -134,7 +135,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
134
135
|
await this.lifecycleHooks.onSignup(user);
|
|
135
136
|
}
|
|
136
137
|
try {
|
|
137
|
-
const verificationCode = await this.verificationService.generateCode(user.email, 'email');
|
|
138
|
+
const verificationCode = await this.verificationService.generateCode(user.email, 'email', realm);
|
|
138
139
|
await this.emailService.sendVerificationEmail(user.email, verificationCode, 15);
|
|
139
140
|
await this.userRepository.update(user.id, {
|
|
140
141
|
emailVerificationSentAt: new Date(),
|
|
@@ -145,17 +146,10 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
145
146
|
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
146
147
|
this.logger.error(`Failed to send verification email to ${user.email}`, errorStack);
|
|
147
148
|
}
|
|
148
|
-
const accessToken = this.
|
|
149
|
-
const { token: refreshToken, hash: refreshTokenHash } = this.refreshTokenService.generateToken();
|
|
150
|
-
await this.refreshTokenRepository.create({
|
|
151
|
-
userId: user.id,
|
|
152
|
-
token: refreshToken,
|
|
153
|
-
hashedToken: refreshTokenHash,
|
|
154
|
-
expiresAt: this.refreshTokenService.getExpiryDate(),
|
|
155
|
-
});
|
|
149
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user, realm);
|
|
156
150
|
return { accessToken, refreshToken, user };
|
|
157
151
|
}
|
|
158
|
-
async login(email, password, ipAddress) {
|
|
152
|
+
async login(email, password, ipAddress, realm) {
|
|
159
153
|
this.logger.log(`[AUTH_SERVICE] Login started for email: ${email}`);
|
|
160
154
|
if (ipAddress && (await this.bruteForceProtection.checkIpRateLimit(ipAddress))) {
|
|
161
155
|
throw new common_1.HttpException({
|
|
@@ -163,7 +157,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
163
157
|
code: 'RATE_LIMIT_EXCEEDED',
|
|
164
158
|
}, common_1.HttpStatus.TOO_MANY_REQUESTS);
|
|
165
159
|
}
|
|
166
|
-
const user = await this.userRepository.findByEmail(email);
|
|
160
|
+
const user = await this.userRepository.findByEmail(email, realm);
|
|
167
161
|
if (user && await this.bruteForceProtection.isAccountLockedById(user.id)) {
|
|
168
162
|
const remainingTime = await this.bruteForceProtection.getRemainingLockoutTimeById(user.id);
|
|
169
163
|
throw new account_locked_exception_1.AccountLockedException(remainingTime);
|
|
@@ -179,7 +173,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
179
173
|
this.lifecycleHooks.onAuthFailure(email, ipAddress, 'USER_NOT_FOUND');
|
|
180
174
|
}
|
|
181
175
|
if (ipAddress) {
|
|
182
|
-
await this.bruteForceProtection.recordFailedAttempt(email, ipAddress);
|
|
176
|
+
await this.bruteForceProtection.recordFailedAttempt(email, ipAddress, undefined, realm);
|
|
183
177
|
}
|
|
184
178
|
throw new common_1.UnauthorizedException('Invalid credentials');
|
|
185
179
|
}
|
|
@@ -198,11 +192,11 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
198
192
|
this.lifecycleHooks.onAuthFailure(email, ipAddress, 'INVALID_PASSWORD');
|
|
199
193
|
}
|
|
200
194
|
if (ipAddress) {
|
|
201
|
-
await this.bruteForceProtection.recordFailedAttempt(email, ipAddress, user.id);
|
|
195
|
+
await this.bruteForceProtection.recordFailedAttempt(email, ipAddress, user.id, realm);
|
|
202
196
|
}
|
|
203
197
|
throw new common_1.UnauthorizedException('Invalid credentials');
|
|
204
198
|
}
|
|
205
|
-
await this.bruteForceProtection.resetFailedAttempts(email);
|
|
199
|
+
await this.bruteForceProtection.resetFailedAttempts(email, realm);
|
|
206
200
|
this.securityLogger.log(auth_logger_interface_1.SecurityEvent.LOGIN_SUCCESS, {
|
|
207
201
|
userId: user.id,
|
|
208
202
|
email,
|
|
@@ -211,17 +205,10 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
211
205
|
if (this.lifecycleHooks.onLogin) {
|
|
212
206
|
await this.lifecycleHooks.onLogin(user);
|
|
213
207
|
}
|
|
214
|
-
const accessToken = this.
|
|
215
|
-
const { token: refreshToken, hash: refreshTokenHash } = this.refreshTokenService.generateToken();
|
|
216
|
-
await this.refreshTokenRepository.create({
|
|
217
|
-
userId: user.id,
|
|
218
|
-
token: refreshToken,
|
|
219
|
-
hashedToken: refreshTokenHash,
|
|
220
|
-
expiresAt: this.refreshTokenService.getExpiryDate(),
|
|
221
|
-
});
|
|
208
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user, realm);
|
|
222
209
|
return { accessToken, refreshToken, user };
|
|
223
210
|
}
|
|
224
|
-
async refreshToken(refreshToken, ipAddress) {
|
|
211
|
+
async refreshToken(refreshToken, ipAddress, realm) {
|
|
225
212
|
try {
|
|
226
213
|
const refreshTokenHash = this.refreshTokenService.hashToken(refreshToken);
|
|
227
214
|
const cachedResult = this.refreshTokenService.getCachedRefreshResult(refreshTokenHash);
|
|
@@ -270,14 +257,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
270
257
|
});
|
|
271
258
|
throw new common_1.UnauthorizedException('User not found');
|
|
272
259
|
}
|
|
273
|
-
const newAccessToken = this.
|
|
274
|
-
const { token: newRefreshToken, hash: newRefreshTokenHash } = this.refreshTokenService.generateToken();
|
|
275
|
-
await this.refreshTokenRepository.create({
|
|
276
|
-
userId: user.id,
|
|
277
|
-
token: newRefreshToken,
|
|
278
|
-
hashedToken: newRefreshTokenHash,
|
|
279
|
-
expiresAt: this.refreshTokenService.getExpiryDate(),
|
|
280
|
-
});
|
|
260
|
+
const { accessToken: newAccessToken, refreshToken: newRefreshToken, refreshTokenHash: newRefreshTokenHash, } = await this.generateTokenPairAndStore(user, realm);
|
|
281
261
|
await this.refreshTokenRepository.delete(storedToken.id);
|
|
282
262
|
await this.refreshTokenRepository.deleteExpired().catch((err) => {
|
|
283
263
|
this.logger.warn(`Failed to clean up expired refresh tokens: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -375,8 +355,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
375
355
|
message: 'Password changed successfully. Please log in again with your new password.',
|
|
376
356
|
};
|
|
377
357
|
}
|
|
378
|
-
async verifyEmail(email, code) {
|
|
379
|
-
const user = await this.userRepository.findByEmail(email);
|
|
358
|
+
async verifyEmail(email, code, realm) {
|
|
359
|
+
const user = await this.userRepository.findByEmail(email, realm);
|
|
380
360
|
if (!user) {
|
|
381
361
|
throw new common_1.UnauthorizedException('Invalid email address');
|
|
382
362
|
}
|
|
@@ -386,7 +366,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
386
366
|
message: 'Email is already verified',
|
|
387
367
|
};
|
|
388
368
|
}
|
|
389
|
-
await this.verificationService.validateCode(email, 'email', code);
|
|
369
|
+
await this.verificationService.validateCode(email, 'email', code, realm);
|
|
390
370
|
await this.userRepository.markEmailVerified(user.id);
|
|
391
371
|
if (this.lifecycleHooks.onEmailVerified) {
|
|
392
372
|
await this.lifecycleHooks.onEmailVerified(user);
|
|
@@ -397,8 +377,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
397
377
|
message: 'Email successfully verified',
|
|
398
378
|
};
|
|
399
379
|
}
|
|
400
|
-
async resendVerificationEmail(email) {
|
|
401
|
-
const user = await this.userRepository.findByEmail(email);
|
|
380
|
+
async resendVerificationEmail(email, realm) {
|
|
381
|
+
const user = await this.userRepository.findByEmail(email, realm);
|
|
402
382
|
if (!user) {
|
|
403
383
|
throw new common_1.UnauthorizedException('Invalid email address');
|
|
404
384
|
}
|
|
@@ -417,8 +397,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
417
397
|
throw new VerificationEmailRateLimitException(retryAfterSeconds);
|
|
418
398
|
}
|
|
419
399
|
}
|
|
420
|
-
await this.verificationService.invalidateCode(email, 'email');
|
|
421
|
-
const verificationCode = await this.verificationService.generateCode(email, 'email');
|
|
400
|
+
await this.verificationService.invalidateCode(email, 'email', realm);
|
|
401
|
+
const verificationCode = await this.verificationService.generateCode(email, 'email', realm);
|
|
422
402
|
try {
|
|
423
403
|
await this.emailService.sendVerificationEmail(email, verificationCode, 15);
|
|
424
404
|
await this.userRepository.update(user.id, {
|
|
@@ -436,7 +416,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
436
416
|
throw new common_1.HttpException('Failed to send verification email. Please try again later.', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
437
417
|
}
|
|
438
418
|
}
|
|
439
|
-
async sendPhoneVerification(userId, phoneNumber, countryCode) {
|
|
419
|
+
async sendPhoneVerification(userId, phoneNumber, countryCode, realm) {
|
|
440
420
|
const user = await this.userRepository.findById(userId);
|
|
441
421
|
if (!user) {
|
|
442
422
|
throw new common_1.UnauthorizedException('User not found');
|
|
@@ -445,7 +425,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
445
425
|
if (!normalizedPhone) {
|
|
446
426
|
throw new common_1.BadRequestException('Invalid phone number format');
|
|
447
427
|
}
|
|
448
|
-
const existingUser = await this.userRepository.findByPhoneNumber(normalizedPhone);
|
|
428
|
+
const existingUser = await this.userRepository.findByPhoneNumber(normalizedPhone, realm);
|
|
449
429
|
if (existingUser && existingUser.id !== userId) {
|
|
450
430
|
throw new common_1.ConflictException('This phone number is already associated with another account');
|
|
451
431
|
}
|
|
@@ -498,9 +478,9 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
498
478
|
user: {
|
|
499
479
|
id: user.id,
|
|
500
480
|
email: user.email,
|
|
501
|
-
phoneNumber: user.phoneNumber,
|
|
502
|
-
phoneVerified: user.phoneVerified,
|
|
503
|
-
phoneVerifiedAt: user.phoneVerifiedAt,
|
|
481
|
+
phoneNumber: user.phoneNumber ?? undefined,
|
|
482
|
+
phoneVerified: user.phoneVerified ?? false,
|
|
483
|
+
phoneVerifiedAt: user.phoneVerifiedAt ?? undefined,
|
|
504
484
|
},
|
|
505
485
|
};
|
|
506
486
|
}
|
|
@@ -531,9 +511,9 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
531
511
|
user: {
|
|
532
512
|
id: updatedUser.id,
|
|
533
513
|
email: updatedUser.email,
|
|
534
|
-
phoneNumber: updatedUser.phoneNumber,
|
|
535
|
-
phoneVerified: updatedUser.phoneVerified,
|
|
536
|
-
phoneVerifiedAt: updatedUser.phoneVerifiedAt,
|
|
514
|
+
phoneNumber: updatedUser.phoneNumber ?? undefined,
|
|
515
|
+
phoneVerified: updatedUser.phoneVerified ?? false,
|
|
516
|
+
phoneVerifiedAt: updatedUser.phoneVerifiedAt ?? undefined,
|
|
537
517
|
},
|
|
538
518
|
};
|
|
539
519
|
}
|
|
@@ -623,30 +603,23 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
623
603
|
},
|
|
624
604
|
};
|
|
625
605
|
}
|
|
626
|
-
async handleSocialLogin(provider, profile, _ipAddress) {
|
|
606
|
+
async handleSocialLogin(provider, profile, _ipAddress, realm) {
|
|
627
607
|
this.logger.log(`[AUTH_SERVICE] Social login started for ${provider}: ${profile.email}`);
|
|
628
608
|
const providerIdField = `${provider}Id`;
|
|
629
609
|
const providerId = profile[providerIdField];
|
|
630
610
|
if (!providerId) {
|
|
631
611
|
throw new common_1.UnauthorizedException(`Missing ${providerIdField} in profile`);
|
|
632
612
|
}
|
|
633
|
-
let user = await this.userRepository.findByOAuthProvider(provider, providerId);
|
|
613
|
+
let user = await this.userRepository.findByOAuthProvider(provider, providerId, realm);
|
|
634
614
|
if (user) {
|
|
635
615
|
this.logger.log(`[AUTH_SERVICE] Existing OAuth user found: ${user.id}`);
|
|
636
616
|
if (this.lifecycleHooks.onLogin) {
|
|
637
617
|
await this.lifecycleHooks.onLogin(user);
|
|
638
618
|
}
|
|
639
|
-
const accessToken = this.
|
|
640
|
-
const { token: refreshToken, hash: refreshTokenHash } = this.refreshTokenService.generateToken();
|
|
641
|
-
await this.refreshTokenRepository.create({
|
|
642
|
-
userId: user.id,
|
|
643
|
-
token: refreshToken,
|
|
644
|
-
hashedToken: refreshTokenHash,
|
|
645
|
-
expiresAt: this.refreshTokenService.getExpiryDate(),
|
|
646
|
-
});
|
|
619
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user, realm);
|
|
647
620
|
return { accessToken, refreshToken, user };
|
|
648
621
|
}
|
|
649
|
-
user = await this.userRepository.findByEmail(profile.email);
|
|
622
|
+
user = await this.userRepository.findByEmail(profile.email, realm);
|
|
650
623
|
if (user) {
|
|
651
624
|
this.logger.log(`[AUTH_SERVICE] Email exists for ${profile.email}, checking account linking`);
|
|
652
625
|
if (user.passwordHash) {
|
|
@@ -676,14 +649,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
676
649
|
if (this.lifecycleHooks.onLogin) {
|
|
677
650
|
await this.lifecycleHooks.onLogin(user);
|
|
678
651
|
}
|
|
679
|
-
const accessToken = this.
|
|
680
|
-
const { token: refreshToken, hash: refreshTokenHash } = this.refreshTokenService.generateToken();
|
|
681
|
-
await this.refreshTokenRepository.create({
|
|
682
|
-
userId: user.id,
|
|
683
|
-
token: refreshToken,
|
|
684
|
-
hashedToken: refreshTokenHash,
|
|
685
|
-
expiresAt: this.refreshTokenService.getExpiryDate(),
|
|
686
|
-
});
|
|
652
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(user, realm);
|
|
687
653
|
return { accessToken, refreshToken, user };
|
|
688
654
|
}
|
|
689
655
|
this.logger.log(`[AUTH_SERVICE] Creating new OAuth user for ${profile.email}`);
|
|
@@ -693,6 +659,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
693
659
|
passwordHash: null,
|
|
694
660
|
emailVerified: true,
|
|
695
661
|
authProvider: providerEnum,
|
|
662
|
+
realm,
|
|
696
663
|
};
|
|
697
664
|
userData[providerIdField] = providerId;
|
|
698
665
|
const newUser = await this.userRepository.create(userData);
|
|
@@ -701,17 +668,10 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
701
668
|
await this.lifecycleHooks.onSignup(newUser);
|
|
702
669
|
}
|
|
703
670
|
this.logger.log(`[AUTH_SERVICE] Lifecycle hooks completed for user: ${newUser.id}`);
|
|
704
|
-
const accessToken = this.
|
|
705
|
-
const { token: refreshToken, hash: refreshTokenHash } = this.refreshTokenService.generateToken();
|
|
706
|
-
await this.refreshTokenRepository.create({
|
|
707
|
-
userId: newUser.id,
|
|
708
|
-
token: refreshToken,
|
|
709
|
-
hashedToken: refreshTokenHash,
|
|
710
|
-
expiresAt: this.refreshTokenService.getExpiryDate(),
|
|
711
|
-
});
|
|
671
|
+
const { accessToken, refreshToken } = await this.generateTokenPairAndStore(newUser, realm);
|
|
712
672
|
return { accessToken, refreshToken, user: newUser };
|
|
713
673
|
}
|
|
714
|
-
async completeFacebookSignUp(fallbackToken, email, accessToken) {
|
|
674
|
+
async completeFacebookSignUp(fallbackToken, email, accessToken, realm) {
|
|
715
675
|
this.logger.log(`[AUTH_SERVICE] ===== COMPLETE FACEBOOK SIGN-UP =====`);
|
|
716
676
|
this.logger.log(`[AUTH_SERVICE] Email: ${email}`);
|
|
717
677
|
let fallbackPayload;
|
|
@@ -741,7 +701,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
741
701
|
throw new oauth_exceptions_1.InvalidOAuthTokenException('facebook', 'Access token does not match Facebook account');
|
|
742
702
|
}
|
|
743
703
|
this.logger.log(`[AUTH_SERVICE] Facebook access token validated and matched facebookId: ${facebookId}`);
|
|
744
|
-
const existingUser = await this.userRepository.findByEmail(email);
|
|
704
|
+
const existingUser = await this.userRepository.findByEmail(email, realm);
|
|
745
705
|
if (existingUser) {
|
|
746
706
|
this.logger.log(`[AUTH_SERVICE] Email exists for ${email}, checking account linking...`);
|
|
747
707
|
if (existingUser.passwordHash) {
|
|
@@ -760,8 +720,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
760
720
|
emailVerified: true,
|
|
761
721
|
emailVerifiedAt: new Date(),
|
|
762
722
|
updatedAt: new Date(),
|
|
723
|
+
facebookId,
|
|
763
724
|
};
|
|
764
|
-
updateData['facebookId'] = facebookId;
|
|
765
725
|
await this.userRepository.update(existingUser.id, updateData);
|
|
766
726
|
const linkedUser = await this.userRepository.findById(existingUser.id);
|
|
767
727
|
if (!linkedUser) {
|
|
@@ -771,14 +731,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
771
731
|
if (this.lifecycleHooks.onLogin) {
|
|
772
732
|
await this.lifecycleHooks.onLogin(linkedUser);
|
|
773
733
|
}
|
|
774
|
-
const jwtAccessToken = this.
|
|
775
|
-
const { token: refreshToken, hash: refreshTokenHash } = this.refreshTokenService.generateToken();
|
|
776
|
-
await this.refreshTokenRepository.create({
|
|
777
|
-
userId: linkedUser.id,
|
|
778
|
-
token: refreshToken,
|
|
779
|
-
hashedToken: refreshTokenHash,
|
|
780
|
-
expiresAt: this.refreshTokenService.getExpiryDate(),
|
|
781
|
-
});
|
|
734
|
+
const { accessToken: jwtAccessToken, refreshToken } = await this.generateTokenPairAndStore(linkedUser, realm);
|
|
782
735
|
this.logger.log(`[AUTH_SERVICE] Facebook account linking complete for user: ${linkedUser.id}`);
|
|
783
736
|
return {
|
|
784
737
|
accessToken: jwtAccessToken,
|
|
@@ -794,6 +747,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
794
747
|
emailVerified: false,
|
|
795
748
|
createdAt: new Date(),
|
|
796
749
|
updatedAt: new Date(),
|
|
750
|
+
realm,
|
|
797
751
|
});
|
|
798
752
|
this.logger.log(`[AUTH_SERVICE] New Facebook user created: ${newUser.id}`);
|
|
799
753
|
if (this.lifecycleHooks.onSignup) {
|
|
@@ -801,7 +755,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
801
755
|
}
|
|
802
756
|
this.logger.log(`[AUTH_SERVICE] Lifecycle hooks completed for user: ${newUser.id}`);
|
|
803
757
|
try {
|
|
804
|
-
const verificationCode = await this.verificationService.generateCode(newUser.email, 'email');
|
|
758
|
+
const verificationCode = await this.verificationService.generateCode(newUser.email, 'email', realm);
|
|
805
759
|
await this.emailService.sendVerificationEmail(newUser.email, verificationCode, 15);
|
|
806
760
|
await this.userRepository.update(newUser.id, {
|
|
807
761
|
emailVerificationSentAt: new Date(),
|
|
@@ -813,14 +767,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
813
767
|
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
814
768
|
this.logger.error(`[AUTH_SERVICE] Failed to send verification email to ${newUser.email}: ${errorMessage}`, errorStack);
|
|
815
769
|
}
|
|
816
|
-
const jwtAccessToken = this.
|
|
817
|
-
const { token: refreshToken, hash: refreshTokenHash } = this.refreshTokenService.generateToken();
|
|
818
|
-
await this.refreshTokenRepository.create({
|
|
819
|
-
userId: newUser.id,
|
|
820
|
-
token: refreshToken,
|
|
821
|
-
hashedToken: refreshTokenHash,
|
|
822
|
-
expiresAt: this.refreshTokenService.getExpiryDate(),
|
|
823
|
-
});
|
|
770
|
+
const { accessToken: jwtAccessToken, refreshToken } = await this.generateTokenPairAndStore(newUser, realm);
|
|
824
771
|
this.logger.log(`[AUTH_SERVICE] Facebook sign-up complete for user: ${newUser.id}`);
|
|
825
772
|
this.logger.log(`[AUTH_SERVICE] NOTE: Email verification required (check email for code)`);
|
|
826
773
|
return { accessToken: jwtAccessToken, refreshToken, user: newUser };
|
|
@@ -829,10 +776,10 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
829
776
|
this.logger.log(`[AUTH_SERVICE] Unlink ${provider} account for user: ${userId}`);
|
|
830
777
|
throw new Error('unlinkSocialAccount transaction not implemented - requires repository with transaction support. See README.md');
|
|
831
778
|
}
|
|
832
|
-
async requestPasswordReset(email, ipAddress) {
|
|
779
|
+
async requestPasswordReset(email, ipAddress, realm) {
|
|
833
780
|
const normalizedEmail = email.toLowerCase();
|
|
834
781
|
if (ipAddress && this.rateLimiter) {
|
|
835
|
-
const ipRateLimitKey = `password-reset:ip:${ipAddress}`;
|
|
782
|
+
const ipRateLimitKey = realm ? `${realm}:password-reset:ip:${ipAddress}` : `password-reset:ip:${ipAddress}`;
|
|
836
783
|
const ipLimit = await this.rateLimiter.checkRateLimit(ipRateLimitKey, 5, 3600000);
|
|
837
784
|
if (!ipLimit.allowed) {
|
|
838
785
|
const retryAfterSeconds = Math.ceil((ipLimit.resetAt.getTime() - Date.now()) / 1000);
|
|
@@ -842,7 +789,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
842
789
|
}
|
|
843
790
|
await this.rateLimiter.recordAttempt(ipRateLimitKey, 3600000);
|
|
844
791
|
}
|
|
845
|
-
const user = await this.userRepository.findByEmail(normalizedEmail);
|
|
792
|
+
const user = await this.userRepository.findByEmail(normalizedEmail, realm);
|
|
846
793
|
if (!user) {
|
|
847
794
|
this.securityLogger.log(auth_logger_interface_1.SecurityEvent.PASSWORD_RESET_REQUESTED, {
|
|
848
795
|
email: normalizedEmail,
|
|
@@ -854,8 +801,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
854
801
|
message: 'If an account exists with this email, a password reset code has been sent.',
|
|
855
802
|
};
|
|
856
803
|
}
|
|
857
|
-
if (await this.bruteForceProtection.isAccountLocked(normalizedEmail)) {
|
|
858
|
-
const remainingTime = await this.bruteForceProtection.getRemainingLockoutTime(normalizedEmail);
|
|
804
|
+
if (await this.bruteForceProtection.isAccountLocked(normalizedEmail, realm)) {
|
|
805
|
+
const remainingTime = await this.bruteForceProtection.getRemainingLockoutTime(normalizedEmail, realm);
|
|
859
806
|
throw new account_locked_exception_1.AccountLockedException(remainingTime);
|
|
860
807
|
}
|
|
861
808
|
if (user.passwordResetSentAt) {
|
|
@@ -874,8 +821,8 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
874
821
|
message: 'If an account exists with this email, a password reset code has been sent.',
|
|
875
822
|
};
|
|
876
823
|
}
|
|
877
|
-
await this.verificationService.invalidateCode(normalizedEmail, 'password-reset');
|
|
878
|
-
const code = await this.verificationService.generateCode(normalizedEmail, 'password-reset');
|
|
824
|
+
await this.verificationService.invalidateCode(normalizedEmail, 'password-reset', realm);
|
|
825
|
+
const code = await this.verificationService.generateCode(normalizedEmail, 'password-reset', realm);
|
|
879
826
|
try {
|
|
880
827
|
const resetUrl = `${process.env.FRONTEND_URL || 'https://app.example.com'}/reset-password`;
|
|
881
828
|
await this.emailService.sendPasswordResetEmail(normalizedEmail, code, resetUrl);
|
|
@@ -903,14 +850,14 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
903
850
|
};
|
|
904
851
|
}
|
|
905
852
|
}
|
|
906
|
-
async resetPassword(email, code, newPassword, ipAddress) {
|
|
853
|
+
async resetPassword(email, code, newPassword, ipAddress, realm) {
|
|
907
854
|
const normalizedEmail = email.toLowerCase();
|
|
908
|
-
const user = await this.userRepository.findByEmail(normalizedEmail);
|
|
855
|
+
const user = await this.userRepository.findByEmail(normalizedEmail, realm);
|
|
909
856
|
if (!user) {
|
|
910
857
|
throw new common_1.UnauthorizedException('Invalid email or verification code');
|
|
911
858
|
}
|
|
912
|
-
if (await this.bruteForceProtection.isAccountLocked(normalizedEmail)) {
|
|
913
|
-
const remainingTime = await this.bruteForceProtection.getRemainingLockoutTime(normalizedEmail);
|
|
859
|
+
if (await this.bruteForceProtection.isAccountLocked(normalizedEmail, realm)) {
|
|
860
|
+
const remainingTime = await this.bruteForceProtection.getRemainingLockoutTime(normalizedEmail, realm);
|
|
914
861
|
throw new account_locked_exception_1.AccountLockedException(remainingTime);
|
|
915
862
|
}
|
|
916
863
|
if (!user.passwordHash) {
|
|
@@ -921,7 +868,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
921
868
|
const { WeakPasswordException } = await Promise.resolve().then(() => __importStar(require('../exceptions/password-reset.exceptions')));
|
|
922
869
|
throw new WeakPasswordException(errors);
|
|
923
870
|
}
|
|
924
|
-
await this.verificationService.validateCode(normalizedEmail, 'password-reset', code);
|
|
871
|
+
await this.verificationService.validateCode(normalizedEmail, 'password-reset', code, realm);
|
|
925
872
|
const passwordHash = await bcrypt.hash(newPassword, this.bcryptRounds);
|
|
926
873
|
const updatedUser = await this.userRepository.updatePassword(user.id, passwordHash);
|
|
927
874
|
await this.refreshTokenRepository.deleteByUserId(user.id);
|
|
@@ -933,9 +880,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
933
880
|
method: 'code',
|
|
934
881
|
});
|
|
935
882
|
try {
|
|
936
|
-
|
|
937
|
-
await this.emailService.sendPasswordChangedEmail(normalizedEmail, new Date(), ipAddress);
|
|
938
|
-
}
|
|
883
|
+
await this.emailService.sendPasswordChangedEmail(normalizedEmail, new Date(), ipAddress);
|
|
939
884
|
}
|
|
940
885
|
catch (error) {
|
|
941
886
|
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
@@ -992,10 +937,24 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
992
937
|
res.clearCookie(accessTokenName, baseOpts);
|
|
993
938
|
res.clearCookie(refreshTokenName, baseOpts);
|
|
994
939
|
}
|
|
995
|
-
|
|
996
|
-
|
|
940
|
+
maskPhoneNumber(phone) {
|
|
941
|
+
return this.smsService.maskPhoneNumber(phone);
|
|
942
|
+
}
|
|
943
|
+
generateToken(user, realm) {
|
|
944
|
+
const payload = this.jwtPayloadFactory.createPayload(realm !== undefined ? { ...user, realm } : user);
|
|
997
945
|
return this.jwtService.sign(payload);
|
|
998
946
|
}
|
|
947
|
+
async generateTokenPairAndStore(user, realm) {
|
|
948
|
+
const accessToken = this.generateToken(user, realm);
|
|
949
|
+
const { token: refreshToken, hash: refreshTokenHash } = this.refreshTokenService.generateToken();
|
|
950
|
+
await this.refreshTokenRepository.create({
|
|
951
|
+
userId: user.id,
|
|
952
|
+
token: refreshToken,
|
|
953
|
+
hashedToken: refreshTokenHash,
|
|
954
|
+
expiresAt: this.refreshTokenService.getExpiryDate(),
|
|
955
|
+
});
|
|
956
|
+
return { accessToken, refreshToken, refreshTokenHash };
|
|
957
|
+
}
|
|
999
958
|
};
|
|
1000
959
|
exports.AuthService = AuthService;
|
|
1001
960
|
AuthService.DUMMY_HASH = '$2b$12$LJ3m4ys3Sxz.f7.v6Jk0XOY/RP7/.NR3WaGy0JH3HxqrP8Q.LRzqy';
|