@flusys/nestjs-auth 4.1.0 → 5.0.0
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 +151 -719
- package/cjs/config/message-keys.js +6 -61
- package/cjs/controllers/authentication.controller.js +113 -87
- package/cjs/controllers/company-selection.controller.js +24 -4
- package/cjs/controllers/email-verification.controller.js +12 -13
- package/cjs/docs/auth-swagger.config.js +143 -106
- package/cjs/dtos/authentication.dto.js +0 -15
- package/cjs/entities/user-company-permission.entity.js +0 -8
- package/cjs/entities/user-token.entity.js +0 -9
- package/cjs/interceptors/set-token.interceptor.js +15 -7
- package/cjs/services/auth-config.service.js +0 -4
- package/cjs/services/auth-email.service.js +8 -31
- package/cjs/services/authentication.service.js +99 -15
- package/cjs/services/user-permission.service.js +6 -8
- package/cjs/services/user.service.js +12 -9
- package/cjs/strategies/jwt.strategy.js +10 -3
- package/config/message-keys.d.ts +5 -153
- package/controllers/authentication.controller.d.ts +6 -7
- package/controllers/company-selection.controller.d.ts +3 -2
- package/controllers/email-verification.controller.d.ts +6 -2
- package/dtos/authentication.dto.d.ts +0 -2
- package/entities/user-company-permission.entity.d.ts +0 -1
- package/entities/user-token.entity.d.ts +0 -1
- package/fesm/config/message-keys.js +6 -53
- package/fesm/controllers/authentication.controller.js +115 -90
- package/fesm/controllers/company-selection.controller.js +25 -5
- package/fesm/controllers/email-verification.controller.js +13 -14
- package/fesm/docs/auth-swagger.config.js +146 -113
- package/fesm/dtos/authentication.dto.js +0 -15
- package/fesm/entities/user-company-permission.entity.js +0 -8
- package/fesm/entities/user-token.entity.js +0 -9
- package/fesm/interceptors/set-token.interceptor.js +15 -7
- package/fesm/services/auth-config.service.js +0 -4
- package/fesm/services/auth-email.service.js +8 -32
- package/fesm/services/authentication.service.js +100 -17
- package/fesm/services/user-permission.service.js +6 -8
- package/fesm/services/user.service.js +12 -10
- package/fesm/strategies/jwt.strategy.js +10 -3
- package/interfaces/auth-module-options.interface.d.ts +0 -1
- package/package.json +3 -3
- package/services/auth-config.service.d.ts +0 -1
- package/services/auth-email.service.d.ts +0 -4
- package/services/authentication.service.d.ts +1 -1
- package/services/user-permission.service.d.ts +1 -1
- package/services/user.service.d.ts +5 -5
|
@@ -13,15 +13,6 @@ _export(exports, {
|
|
|
13
13
|
get AUTH_MESSAGES () {
|
|
14
14
|
return AUTH_MESSAGES;
|
|
15
15
|
},
|
|
16
|
-
get AUTH_MODULE_MESSAGES () {
|
|
17
|
-
return AUTH_MODULE_MESSAGES;
|
|
18
|
-
},
|
|
19
|
-
get BRANCH_MESSAGES () {
|
|
20
|
-
return BRANCH_MESSAGES;
|
|
21
|
-
},
|
|
22
|
-
get COMPANY_MESSAGES () {
|
|
23
|
-
return COMPANY_MESSAGES;
|
|
24
|
-
},
|
|
25
16
|
get EMAIL_VERIFICATION_MESSAGES () {
|
|
26
17
|
return EMAIL_VERIFICATION_MESSAGES;
|
|
27
18
|
},
|
|
@@ -34,31 +25,29 @@ _export(exports, {
|
|
|
34
25
|
});
|
|
35
26
|
const AUTH_MESSAGES = {
|
|
36
27
|
LOGIN_SUCCESS: 'auth.login.success',
|
|
37
|
-
|
|
28
|
+
LOGIN_REQUIRES_SELECTION: 'auth.login.requires.selection',
|
|
38
29
|
LOGIN_INVALID_CREDENTIALS: 'auth.login.invalid.credentials',
|
|
39
30
|
LOGIN_EMAIL_NOT_VERIFIED: 'auth.login.email.not.verified',
|
|
40
|
-
LOGIN_REQUIRES_SELECTION: 'auth.login.requires.selection',
|
|
41
31
|
LOGIN_ACCOUNT_DEACTIVATED: 'auth.login.account.deactivated',
|
|
42
32
|
LOGOUT_SUCCESS: 'auth.logout.success',
|
|
43
33
|
REGISTER_SUCCESS: 'auth.register.success',
|
|
44
34
|
REGISTER_FAILED: 'auth.register.failed',
|
|
35
|
+
REFRESH_SUCCESS: 'auth.refresh.success',
|
|
36
|
+
ME_SUCCESS: 'auth.me.success',
|
|
37
|
+
SELECT_SUCCESS: 'auth.select.success',
|
|
38
|
+
SWITCH_COMPANY_SUCCESS: 'auth.switch.company.success',
|
|
45
39
|
REGISTER_EMAIL_EXISTS: 'auth.register.email.exists',
|
|
46
40
|
REGISTER_COMPANY_ALREADY_ASSIGNED: 'auth.register.company.already.assigned',
|
|
47
41
|
PASSWORD_CHANGE_SUCCESS: 'auth.password.change.success',
|
|
48
|
-
PASSWORD_CHANGE_FAILED: 'auth.password.change.failed',
|
|
49
42
|
PASSWORD_CHANGE_INVALID_CURRENT: 'auth.password.change.invalid.current',
|
|
50
43
|
PASSWORD_CHANGE_CURRENT_REQUIRED: 'auth.password.change.current.required',
|
|
51
44
|
PASSWORD_RESET_EMAIL_SENT: 'auth.password.reset.email.sent',
|
|
52
45
|
PASSWORD_RESET_SUCCESS: 'auth.password.reset.success',
|
|
53
|
-
PASSWORD_RESET_FAILED: 'auth.password.reset.failed',
|
|
54
|
-
TOKEN_REFRESH_SUCCESS: 'auth.token.refresh.success',
|
|
55
46
|
TOKEN_REQUIRED: 'auth.token.required',
|
|
56
47
|
TOKEN_INVALID: 'auth.token.invalid',
|
|
57
48
|
TOKEN_EXPIRED: 'auth.token.expired',
|
|
58
49
|
TOKEN_REVOKED: 'auth.token.revoked',
|
|
59
50
|
TOKEN_TOO_LARGE: 'auth.token.too.large',
|
|
60
|
-
COMPANY_SELECT_SUCCESS: 'auth.company.select.success',
|
|
61
|
-
COMPANY_SWITCH_SUCCESS: 'auth.company.switch.success',
|
|
62
51
|
COMPANY_LIST_SUCCESS: 'auth.company.list.success',
|
|
63
52
|
COMPANY_NO_ACCESS: 'auth.company.no.access',
|
|
64
53
|
COMPANY_NOT_FOUND: 'auth.company.not.found',
|
|
@@ -67,7 +56,6 @@ const AUTH_MESSAGES = {
|
|
|
67
56
|
BRANCH_LIST_SUCCESS: 'auth.branch.list.success',
|
|
68
57
|
BRANCH_NO_ACCESS: 'auth.branch.no.access',
|
|
69
58
|
BRANCH_NOT_FOUND: 'auth.branch.not.found',
|
|
70
|
-
ME_SUCCESS: 'auth.me.success',
|
|
71
59
|
EMAIL_NOT_CONFIGURED: 'auth.email.not.configured',
|
|
72
60
|
EMAIL_SEND_FAILED: 'auth.email.send.failed',
|
|
73
61
|
SESSION_INVALID: 'auth.session.invalid',
|
|
@@ -81,24 +69,13 @@ const AUTH_MESSAGES = {
|
|
|
81
69
|
const EMAIL_VERIFICATION_MESSAGES = {
|
|
82
70
|
VERIFICATION_SENT: 'email.verification.sent',
|
|
83
71
|
VERIFICATION_SUCCESS: 'email.verification.success',
|
|
84
|
-
VERIFICATION_FAILED: 'email.verification.failed',
|
|
85
72
|
VERIFICATION_TOKEN_INVALID: 'email.verification.token.invalid',
|
|
86
73
|
VERIFICATION_TOKEN_EXPIRED: 'email.verification.token.expired',
|
|
87
74
|
VERIFICATION_NOT_ENABLED: 'email.verification.not.enabled',
|
|
88
|
-
RESEND_SUCCESS: 'email.verification.resend.success'
|
|
89
|
-
RESEND_THROTTLED: 'email.verification.resend.throttled'
|
|
75
|
+
RESEND_SUCCESS: 'email.verification.resend.success'
|
|
90
76
|
};
|
|
91
77
|
const USER_MESSAGES = {
|
|
92
|
-
CREATE_SUCCESS: 'user.create.success',
|
|
93
|
-
CREATE_MANY_SUCCESS: 'user.create.many.success',
|
|
94
|
-
GET_SUCCESS: 'user.get.success',
|
|
95
|
-
GET_ALL_SUCCESS: 'user.get.all.success',
|
|
96
|
-
UPDATE_SUCCESS: 'user.update.success',
|
|
97
|
-
UPDATE_MANY_SUCCESS: 'user.update.many.success',
|
|
98
|
-
DELETE_SUCCESS: 'user.delete.success',
|
|
99
|
-
RESTORE_SUCCESS: 'user.restore.success',
|
|
100
78
|
NOT_FOUND: 'user.not.found',
|
|
101
|
-
PROFILE_SUCCESS: 'user.profile.success',
|
|
102
79
|
PROFILE_UPDATE_SUCCESS: 'user.profile.update.success',
|
|
103
80
|
PROFILE_EXTRAS_SUCCESS: 'user.profile.extras.success',
|
|
104
81
|
PROFILE_SECTIONS_SUCCESS: 'user.profile.sections.success',
|
|
@@ -109,42 +86,10 @@ const USER_MESSAGES = {
|
|
|
109
86
|
PHONE_VERIFY_SUCCESS: 'user.phone.verify.success',
|
|
110
87
|
STATUS_UPDATE_SUCCESS: 'user.status.update.success'
|
|
111
88
|
};
|
|
112
|
-
const COMPANY_MESSAGES = {
|
|
113
|
-
CREATE_SUCCESS: 'company.create.success',
|
|
114
|
-
CREATE_MANY_SUCCESS: 'company.create.many.success',
|
|
115
|
-
GET_SUCCESS: 'company.get.success',
|
|
116
|
-
GET_ALL_SUCCESS: 'company.get.all.success',
|
|
117
|
-
UPDATE_SUCCESS: 'company.update.success',
|
|
118
|
-
UPDATE_MANY_SUCCESS: 'company.update.many.success',
|
|
119
|
-
DELETE_SUCCESS: 'company.delete.success',
|
|
120
|
-
RESTORE_SUCCESS: 'company.restore.success',
|
|
121
|
-
NOT_FOUND: 'company.not.found'
|
|
122
|
-
};
|
|
123
|
-
const BRANCH_MESSAGES = {
|
|
124
|
-
CREATE_SUCCESS: 'branch.create.success',
|
|
125
|
-
CREATE_MANY_SUCCESS: 'branch.create.many.success',
|
|
126
|
-
GET_SUCCESS: 'branch.get.success',
|
|
127
|
-
GET_ALL_SUCCESS: 'branch.get.all.success',
|
|
128
|
-
UPDATE_SUCCESS: 'branch.update.success',
|
|
129
|
-
UPDATE_MANY_SUCCESS: 'branch.update.many.success',
|
|
130
|
-
DELETE_SUCCESS: 'branch.delete.success',
|
|
131
|
-
RESTORE_SUCCESS: 'branch.restore.success',
|
|
132
|
-
NOT_FOUND: 'branch.not.found'
|
|
133
|
-
};
|
|
134
89
|
const USER_PERMISSION_MESSAGES = {
|
|
135
|
-
COMPANY_ASSIGN_SUCCESS: 'user.permission.company.assign.success',
|
|
136
90
|
COMPANY_LIST_SUCCESS: 'user.permission.company.list.success',
|
|
137
|
-
BRANCH_ASSIGN_SUCCESS: 'user.permission.branch.assign.success',
|
|
138
91
|
BRANCH_LIST_SUCCESS: 'user.permission.branch.list.success',
|
|
139
92
|
BATCH_SUCCESS: 'user.permission.batch.success',
|
|
140
93
|
ALREADY_ASSIGNED: 'user.permission.already.assigned',
|
|
141
94
|
PERMISSION_NOT_FOUND: 'user.permission.not.found'
|
|
142
95
|
};
|
|
143
|
-
const AUTH_MODULE_MESSAGES = {
|
|
144
|
-
AUTH: AUTH_MESSAGES,
|
|
145
|
-
EMAIL_VERIFICATION: EMAIL_VERIFICATION_MESSAGES,
|
|
146
|
-
USER: USER_MESSAGES,
|
|
147
|
-
COMPANY: COMPANY_MESSAGES,
|
|
148
|
-
BRANCH: BRANCH_MESSAGES,
|
|
149
|
-
USER_PERMISSION: USER_PERMISSION_MESSAGES
|
|
150
|
-
};
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "AuthenticationController", {
|
|
|
8
8
|
return AuthenticationController;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const _nestjsshared = require("@flusys/nestjs-shared");
|
|
12
12
|
const _decorators = require("@flusys/nestjs-shared/decorators");
|
|
13
13
|
const _dtos = require("@flusys/nestjs-shared/dtos");
|
|
14
14
|
const _guards = require("@flusys/nestjs-shared/guards");
|
|
@@ -17,6 +17,7 @@ const _common = require("@nestjs/common");
|
|
|
17
17
|
const _swagger = require("@nestjs/swagger");
|
|
18
18
|
const _throttler = require("@nestjs/throttler");
|
|
19
19
|
const _express = require("express");
|
|
20
|
+
const _config = require("../config");
|
|
20
21
|
const _authenticationdto = require("../dtos/authentication.dto");
|
|
21
22
|
const _cleartokeninterceptor = require("../interceptors/clear-token.interceptor");
|
|
22
23
|
const _settokeninterceptor = require("../interceptors/set-token.interceptor");
|
|
@@ -50,24 +51,40 @@ function _ts_param(paramIndex, decorator) {
|
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
let AuthenticationController = class AuthenticationController {
|
|
53
|
-
buildAuthUrl(req, path) {
|
|
54
|
-
const frontendUrl = this.authConfig?.getFrontendUrl();
|
|
55
|
-
return frontendUrl ? `${frontendUrl}${path}` : `${req.protocol}://${req.get('host')}${path}`;
|
|
56
|
-
}
|
|
57
54
|
async login(loginDto) {
|
|
58
55
|
const result = await this.authService.login(loginDto.email, loginDto.password);
|
|
59
56
|
if ('requiresEmailVerification' in result) {
|
|
60
|
-
return
|
|
57
|
+
return {
|
|
58
|
+
success: true,
|
|
59
|
+
message: 'Email verification required',
|
|
60
|
+
messageKey: _config.AUTH_MESSAGES.LOGIN_EMAIL_NOT_VERIFIED,
|
|
61
|
+
data: result
|
|
62
|
+
};
|
|
61
63
|
}
|
|
62
64
|
if ('requiresSelection' in result) {
|
|
63
|
-
return
|
|
65
|
+
return {
|
|
66
|
+
success: true,
|
|
67
|
+
message: 'Company selection required',
|
|
68
|
+
messageKey: _config.AUTH_MESSAGES.LOGIN_REQUIRES_SELECTION,
|
|
69
|
+
data: result
|
|
70
|
+
};
|
|
64
71
|
}
|
|
65
|
-
return
|
|
72
|
+
return {
|
|
73
|
+
success: true,
|
|
74
|
+
message: 'Login successful',
|
|
75
|
+
messageKey: _config.AUTH_MESSAGES.LOGIN_SUCCESS,
|
|
76
|
+
data: result
|
|
77
|
+
};
|
|
66
78
|
}
|
|
67
79
|
/** Register new user. If company feature enabled, can join/create company. */ async register(req, registrationDto) {
|
|
68
|
-
const verifyUrlBase =
|
|
80
|
+
const verifyUrlBase = (0, _nestjsshared.buildFrontendUrl)(req, '/auth/verify-email');
|
|
69
81
|
const result = await this.authService.register(registrationDto, verifyUrlBase);
|
|
70
|
-
return
|
|
82
|
+
return {
|
|
83
|
+
success: true,
|
|
84
|
+
message: result.requiresEmailVerification ? 'Verification email sent' : 'Registration successful',
|
|
85
|
+
messageKey: result.requiresEmailVerification ? _config.EMAIL_VERIFICATION_MESSAGES.VERIFICATION_SENT : _config.AUTH_MESSAGES.REGISTER_SUCCESS,
|
|
86
|
+
data: result
|
|
87
|
+
};
|
|
71
88
|
}
|
|
72
89
|
/**
|
|
73
90
|
* Refresh access token.
|
|
@@ -83,10 +100,22 @@ let AuthenticationController = class AuthenticationController {
|
|
|
83
100
|
messageKey: _config.AUTH_MESSAGES.TOKEN_REQUIRED
|
|
84
101
|
});
|
|
85
102
|
}
|
|
86
|
-
|
|
103
|
+
const data = await this.authService.refreshToken(refreshToken);
|
|
104
|
+
return {
|
|
105
|
+
success: true,
|
|
106
|
+
message: 'Token refreshed successfully',
|
|
107
|
+
messageKey: _config.AUTH_MESSAGES.REFRESH_SUCCESS,
|
|
108
|
+
data
|
|
109
|
+
};
|
|
87
110
|
}
|
|
88
111
|
/** Get current user info. Returns user, company, and branch data (no tokens). */ async getCurrentUser(user) {
|
|
89
|
-
|
|
112
|
+
const data = await this.authService.getUserInfo(user.id, user.companyId, user.branchId);
|
|
113
|
+
return {
|
|
114
|
+
success: true,
|
|
115
|
+
message: 'User info retrieved successfully',
|
|
116
|
+
messageKey: _config.AUTH_MESSAGES.ME_SUCCESS,
|
|
117
|
+
data
|
|
118
|
+
};
|
|
90
119
|
}
|
|
91
120
|
/** Logout - Clears refresh token cookie for browsers */ async logout(userId) {
|
|
92
121
|
await this.authService.logout(userId);
|
|
@@ -127,97 +156,93 @@ _ts_decorate([
|
|
|
127
156
|
(0, _swagger.ApiBody)({
|
|
128
157
|
type: _authenticationdto.LoginDto
|
|
129
158
|
}),
|
|
130
|
-
(0, _swagger.ApiExtraModels)(_authenticationdto.LoginResponseDto, _authenticationdto.CompanySelectionResponseDto, _authenticationdto.LoginResponseRequiresEmailVerificationDto),
|
|
131
159
|
(0, _swagger.ApiResponse)({
|
|
132
160
|
status: 200,
|
|
133
161
|
description: 'Login successful, requires company selection, or requires email verification',
|
|
134
162
|
content: {
|
|
135
163
|
'application/json': {
|
|
136
|
-
schema: {
|
|
137
|
-
oneOf: [
|
|
138
|
-
{
|
|
139
|
-
$ref: (0, _swagger.getSchemaPath)(_authenticationdto.LoginResponseDto)
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
$ref: (0, _swagger.getSchemaPath)(_authenticationdto.CompanySelectionResponseDto)
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
$ref: (0, _swagger.getSchemaPath)(_authenticationdto.LoginResponseRequiresEmailVerificationDto)
|
|
146
|
-
}
|
|
147
|
-
]
|
|
148
|
-
},
|
|
149
164
|
examples: {
|
|
150
165
|
loginSuccess: {
|
|
151
166
|
summary: 'Login Success',
|
|
152
|
-
description: 'Successful login with tokens (company/branch included when company feature enabled)',
|
|
153
167
|
value: {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
168
|
+
success: true,
|
|
169
|
+
message: 'Login successful',
|
|
170
|
+
messageKey: 'auth.login.success',
|
|
171
|
+
data: {
|
|
172
|
+
accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
|
173
|
+
user: {
|
|
174
|
+
id: '550e8400-e29b-41d4-a716-446655440000',
|
|
175
|
+
email: 'john@example.com',
|
|
176
|
+
name: 'John Doe'
|
|
177
|
+
}
|
|
160
178
|
}
|
|
161
179
|
}
|
|
162
180
|
},
|
|
163
181
|
loginSuccessWithCompany: {
|
|
164
|
-
summary: 'Login Success (
|
|
165
|
-
description: 'Login with company/branch - only when company feature is enabled',
|
|
182
|
+
summary: 'Login Success (with company/branch)',
|
|
166
183
|
value: {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
184
|
+
success: true,
|
|
185
|
+
message: 'Login successful',
|
|
186
|
+
messageKey: 'auth.login.success',
|
|
187
|
+
data: {
|
|
188
|
+
accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
|
189
|
+
user: {
|
|
190
|
+
id: '550e8400-e29b-41d4-a716-446655440000',
|
|
191
|
+
email: 'john@example.com',
|
|
192
|
+
name: 'John Doe'
|
|
193
|
+
},
|
|
194
|
+
company: {
|
|
195
|
+
id: 'company-id',
|
|
196
|
+
name: 'Acme Corp'
|
|
197
|
+
},
|
|
198
|
+
branch: {
|
|
199
|
+
id: 'branch-id',
|
|
200
|
+
name: 'Main Branch'
|
|
201
|
+
}
|
|
183
202
|
}
|
|
184
203
|
}
|
|
185
204
|
},
|
|
186
205
|
companySelection: {
|
|
187
|
-
summary: 'Company Selection Required
|
|
188
|
-
description: 'User has multiple companies/branches - only when company feature is enabled',
|
|
206
|
+
summary: 'Company Selection Required',
|
|
189
207
|
value: {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
success: true,
|
|
209
|
+
message: 'Company selection required',
|
|
210
|
+
messageKey: 'auth.login.requires.selection',
|
|
211
|
+
data: {
|
|
212
|
+
requiresSelection: true,
|
|
213
|
+
sessionId: 'sess_abc123def456',
|
|
214
|
+
expiresAt: '2024-12-18T15:30:00.000Z',
|
|
215
|
+
user: {
|
|
216
|
+
id: '550e8400-e29b-41d4-a716-446655440000',
|
|
217
|
+
email: 'john@example.com'
|
|
218
|
+
},
|
|
219
|
+
companies: [
|
|
220
|
+
{
|
|
221
|
+
id: 'company-id',
|
|
222
|
+
name: 'Acme Corp',
|
|
223
|
+
slug: 'acme-corp',
|
|
224
|
+
branches: [
|
|
225
|
+
{
|
|
226
|
+
id: 'branch-id',
|
|
227
|
+
name: 'Main Branch',
|
|
228
|
+
slug: 'main-branch'
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
}
|
|
212
234
|
}
|
|
213
235
|
},
|
|
214
236
|
emailVerification: {
|
|
215
237
|
summary: 'Email Verification Required',
|
|
216
|
-
description: 'User must verify email before logging in',
|
|
217
238
|
value: {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
239
|
+
success: true,
|
|
240
|
+
message: 'Email verification required',
|
|
241
|
+
messageKey: 'auth.login.email.not.verified',
|
|
242
|
+
data: {
|
|
243
|
+
requiresEmailVerification: true,
|
|
244
|
+
email: 'john@example.com'
|
|
245
|
+
}
|
|
221
246
|
}
|
|
222
247
|
}
|
|
223
248
|
}
|
|
@@ -249,7 +274,7 @@ _ts_decorate([
|
|
|
249
274
|
}),
|
|
250
275
|
(0, _swagger.ApiResponse)({
|
|
251
276
|
status: 201,
|
|
252
|
-
|
|
277
|
+
description: 'Registration successful or email verification required'
|
|
253
278
|
}),
|
|
254
279
|
_ts_param(0, (0, _common.Req)()),
|
|
255
280
|
_ts_param(1, (0, _common.Body)()),
|
|
@@ -293,13 +318,14 @@ Set header \`x-client-type: mobile\` or \`x-client-type: api\` to identify as no
|
|
|
293
318
|
}),
|
|
294
319
|
(0, _swagger.ApiResponse)({
|
|
295
320
|
status: 200,
|
|
296
|
-
description: '
|
|
321
|
+
description: 'Token refreshed successfully',
|
|
297
322
|
schema: {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
323
|
+
example: {
|
|
324
|
+
success: true,
|
|
325
|
+
message: 'Token refreshed successfully',
|
|
326
|
+
messageKey: 'auth.refresh.success',
|
|
327
|
+
data: {
|
|
328
|
+
accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
|
|
303
329
|
}
|
|
304
330
|
}
|
|
305
331
|
}
|
|
@@ -327,7 +353,7 @@ _ts_decorate([
|
|
|
327
353
|
}),
|
|
328
354
|
(0, _swagger.ApiResponse)({
|
|
329
355
|
status: 200,
|
|
330
|
-
|
|
356
|
+
description: 'Current user info retrieved successfully'
|
|
331
357
|
}),
|
|
332
358
|
_ts_param(0, (0, _decorators.CurrentUser)()),
|
|
333
359
|
_ts_metadata("design:type", Function),
|
|
@@ -45,10 +45,22 @@ function _ts_param(paramIndex, decorator) {
|
|
|
45
45
|
}
|
|
46
46
|
let CompanySelectionController = class CompanySelectionController {
|
|
47
47
|
async select(dto) {
|
|
48
|
-
|
|
48
|
+
const data = await this.authService.select(dto.sessionId, dto.companyId, dto.branchId);
|
|
49
|
+
return {
|
|
50
|
+
success: true,
|
|
51
|
+
message: 'Company selected successfully',
|
|
52
|
+
messageKey: _config.AUTH_MESSAGES.SELECT_SUCCESS,
|
|
53
|
+
data
|
|
54
|
+
};
|
|
49
55
|
}
|
|
50
56
|
async switchCompany(userId, dto) {
|
|
51
|
-
|
|
57
|
+
const data = await this.authService.switchCompany(userId, dto.companyId, dto.branchId);
|
|
58
|
+
return {
|
|
59
|
+
success: true,
|
|
60
|
+
message: 'Company switched successfully',
|
|
61
|
+
messageKey: _config.AUTH_MESSAGES.SWITCH_COMPANY_SUCCESS,
|
|
62
|
+
data
|
|
63
|
+
};
|
|
52
64
|
}
|
|
53
65
|
async getUserCompanies(userId) {
|
|
54
66
|
const companies = await this.authService.getUserCompanies(userId);
|
|
@@ -86,7 +98,7 @@ _ts_decorate([
|
|
|
86
98
|
}),
|
|
87
99
|
(0, _swagger.ApiResponse)({
|
|
88
100
|
status: 200,
|
|
89
|
-
|
|
101
|
+
description: 'Company selected, tokens returned'
|
|
90
102
|
}),
|
|
91
103
|
_ts_param(0, (0, _common.Body)()),
|
|
92
104
|
_ts_metadata("design:type", Function),
|
|
@@ -110,7 +122,7 @@ _ts_decorate([
|
|
|
110
122
|
}),
|
|
111
123
|
(0, _swagger.ApiResponse)({
|
|
112
124
|
status: 200,
|
|
113
|
-
|
|
125
|
+
description: 'Company switched, new tokens returned'
|
|
114
126
|
}),
|
|
115
127
|
_ts_param(0, (0, _decorators.CurrentUser)('id')),
|
|
116
128
|
_ts_param(1, (0, _common.Body)()),
|
|
@@ -130,6 +142,10 @@ _ts_decorate([
|
|
|
130
142
|
summary: "Get user's available companies",
|
|
131
143
|
description: 'Get list of companies the current user has access to'
|
|
132
144
|
}),
|
|
145
|
+
(0, _swagger.ApiResponse)({
|
|
146
|
+
status: 200,
|
|
147
|
+
description: 'User companies retrieved successfully'
|
|
148
|
+
}),
|
|
133
149
|
_ts_param(0, (0, _decorators.CurrentUser)('id')),
|
|
134
150
|
_ts_metadata("design:type", Function),
|
|
135
151
|
_ts_metadata("design:paramtypes", [
|
|
@@ -158,6 +174,10 @@ _ts_decorate([
|
|
|
158
174
|
]
|
|
159
175
|
}
|
|
160
176
|
}),
|
|
177
|
+
(0, _swagger.ApiResponse)({
|
|
178
|
+
status: 200,
|
|
179
|
+
description: 'Company branches retrieved successfully'
|
|
180
|
+
}),
|
|
161
181
|
_ts_param(0, (0, _decorators.CurrentUser)('id')),
|
|
162
182
|
_ts_param(1, (0, _common.Body)('companyId')),
|
|
163
183
|
_ts_metadata("design:type", Function),
|
|
@@ -8,12 +8,13 @@ Object.defineProperty(exports, "EmailVerificationController", {
|
|
|
8
8
|
return EmailVerificationController;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const _nestjsshared = require("@flusys/nestjs-shared");
|
|
12
12
|
const _dtos = require("@flusys/nestjs-shared/dtos");
|
|
13
13
|
const _common = require("@nestjs/common");
|
|
14
14
|
const _swagger = require("@nestjs/swagger");
|
|
15
15
|
const _throttler = require("@nestjs/throttler");
|
|
16
16
|
const _express = require("express");
|
|
17
|
+
const _config = require("../config");
|
|
17
18
|
const _authenticationdto = require("../dtos/authentication.dto");
|
|
18
19
|
const _settokeninterceptor = require("../interceptors/set-token.interceptor");
|
|
19
20
|
const _authconfigservice = require("../services/auth-config.service");
|
|
@@ -56,13 +57,9 @@ let EmailVerificationController = class EmailVerificationController {
|
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
buildAuthUrl(req, path) {
|
|
60
|
-
const frontendUrl = this.authConfig.getFrontendUrl();
|
|
61
|
-
return frontendUrl ? `${frontendUrl}${path}` : `${req.protocol}://${req.get('host')}${path}`;
|
|
62
|
-
}
|
|
63
60
|
async forgotPassword(req, dto) {
|
|
64
61
|
this.ensureEmailVerificationEnabled();
|
|
65
|
-
return this.authEmailService.forgotPassword(dto.email,
|
|
62
|
+
return this.authEmailService.forgotPassword(dto.email, (0, _nestjsshared.buildFrontendUrl)(req, '/auth/reset-password'));
|
|
66
63
|
}
|
|
67
64
|
async resetPassword(dto) {
|
|
68
65
|
this.ensureEmailVerificationEnabled();
|
|
@@ -70,13 +67,19 @@ let EmailVerificationController = class EmailVerificationController {
|
|
|
70
67
|
}
|
|
71
68
|
async resendVerification(req, dto) {
|
|
72
69
|
this.ensureEmailVerificationEnabled();
|
|
73
|
-
return this.authEmailService.resendVerificationEmail(dto.email,
|
|
70
|
+
return this.authEmailService.resendVerificationEmail(dto.email, (0, _nestjsshared.buildFrontendUrl)(req, '/auth/verify-email'));
|
|
74
71
|
}
|
|
75
72
|
async verifyEmail(dto) {
|
|
76
73
|
this.ensureEmailVerificationEnabled();
|
|
77
74
|
const result = await this.authEmailService.verifyEmail(dto.token);
|
|
78
75
|
if (result.type === 'pending') {
|
|
79
|
-
|
|
76
|
+
const data = await this.authService.createUserFromPendingRegistration(result.pending);
|
|
77
|
+
return {
|
|
78
|
+
success: true,
|
|
79
|
+
message: 'Registration completed successfully',
|
|
80
|
+
messageKey: _config.AUTH_MESSAGES.REGISTER_SUCCESS,
|
|
81
|
+
data
|
|
82
|
+
};
|
|
80
83
|
}
|
|
81
84
|
return {
|
|
82
85
|
success: true,
|
|
@@ -195,11 +198,7 @@ _ts_decorate([
|
|
|
195
198
|
}),
|
|
196
199
|
(0, _swagger.ApiResponse)({
|
|
197
200
|
status: 200,
|
|
198
|
-
|
|
199
|
-
}),
|
|
200
|
-
(0, _swagger.ApiResponse)({
|
|
201
|
-
status: 200,
|
|
202
|
-
type: _authenticationdto.RegistrationResponseDto
|
|
201
|
+
description: 'Email verified or registration completed'
|
|
203
202
|
}),
|
|
204
203
|
_ts_param(0, (0, _common.Body)()),
|
|
205
204
|
_ts_metadata("design:type", Function),
|