nesthub 1.0.3 → 1.2.0-alpha.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 +58 -8
- package/dist/auth/README.md +346 -0
- package/dist/auth/auth.constants.d.ts +13 -0
- package/dist/auth/auth.constants.js +17 -0
- package/dist/auth/auth.constants.js.map +1 -0
- package/dist/auth/auth.module.d.ts +10 -0
- package/dist/auth/auth.module.js +275 -0
- package/dist/auth/auth.module.js.map +1 -0
- package/dist/auth/controllers/admin.controller.d.ts +13 -0
- package/dist/auth/controllers/admin.controller.js +73 -0
- package/dist/auth/controllers/admin.controller.js.map +1 -0
- package/dist/auth/controllers/auth.controller.d.ts +29 -0
- package/dist/auth/controllers/auth.controller.js +258 -0
- package/dist/auth/controllers/auth.controller.js.map +1 -0
- package/dist/auth/controllers/passkey.controller.d.ts +35 -0
- package/dist/auth/controllers/passkey.controller.js +175 -0
- package/dist/auth/controllers/passkey.controller.js.map +1 -0
- package/dist/auth/controllers/two-factor.controller.d.ts +29 -0
- package/dist/auth/controllers/two-factor.controller.js +146 -0
- package/dist/auth/controllers/two-factor.controller.js.map +1 -0
- package/dist/auth/decorators/current-user.decorator.d.ts +2 -0
- package/dist/auth/decorators/current-user.decorator.js +12 -0
- package/dist/auth/decorators/current-user.decorator.js.map +1 -0
- package/dist/auth/decorators/public.decorator.d.ts +2 -0
- package/dist/auth/decorators/public.decorator.js +8 -0
- package/dist/auth/decorators/public.decorator.js.map +1 -0
- package/dist/auth/decorators/roles.decorator.d.ts +2 -0
- package/dist/auth/decorators/roles.decorator.js +8 -0
- package/dist/auth/decorators/roles.decorator.js.map +1 -0
- package/dist/auth/entities/account.entity.d.ts +20 -0
- package/dist/auth/entities/account.entity.js +108 -0
- package/dist/auth/entities/account.entity.js.map +1 -0
- package/dist/auth/entities/passkey.entity.d.ts +15 -0
- package/dist/auth/entities/passkey.entity.js +82 -0
- package/dist/auth/entities/passkey.entity.js.map +1 -0
- package/dist/auth/entities/token-session.entity.d.ts +14 -0
- package/dist/auth/entities/token-session.entity.js +80 -0
- package/dist/auth/entities/token-session.entity.js.map +1 -0
- package/dist/auth/entities/user.entity.d.ts +25 -0
- package/dist/auth/entities/user.entity.js +124 -0
- package/dist/auth/entities/user.entity.js.map +1 -0
- package/dist/auth/entities/verification.entity.d.ts +11 -0
- package/dist/auth/entities/verification.entity.js +62 -0
- package/dist/auth/entities/verification.entity.js.map +1 -0
- package/dist/auth/guards/auth.guard.d.ts +17 -0
- package/dist/auth/guards/auth.guard.js +93 -0
- package/dist/auth/guards/auth.guard.js.map +1 -0
- package/dist/auth/guards/roles.guard.d.ts +7 -0
- package/dist/auth/guards/roles.guard.js +44 -0
- package/dist/auth/guards/roles.guard.js.map +1 -0
- package/dist/auth/guards/two-factor.guard.d.ts +4 -0
- package/dist/auth/guards/two-factor.guard.js +30 -0
- package/dist/auth/guards/two-factor.guard.js.map +1 -0
- package/dist/auth/index.d.ts +27 -0
- package/dist/auth/index.js +57 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/interfaces.d.ts +281 -0
- package/dist/auth/interfaces.js +3 -0
- package/dist/auth/interfaces.js.map +1 -0
- package/dist/auth/responses.d.ts +173 -0
- package/dist/auth/responses.js +679 -0
- package/dist/auth/responses.js.map +1 -0
- package/dist/auth/services/anonymous.service.d.ts +8 -0
- package/dist/auth/services/anonymous.service.js +46 -0
- package/dist/auth/services/anonymous.service.js.map +1 -0
- package/dist/auth/services/auth.service.d.ts +35 -0
- package/dist/auth/services/auth.service.js +492 -0
- package/dist/auth/services/auth.service.js.map +1 -0
- package/dist/auth/services/magic-link.service.d.ts +18 -0
- package/dist/auth/services/magic-link.service.js +110 -0
- package/dist/auth/services/magic-link.service.js.map +1 -0
- package/dist/auth/services/oauth.service.d.ts +24 -0
- package/dist/auth/services/oauth.service.js +178 -0
- package/dist/auth/services/oauth.service.js.map +1 -0
- package/dist/auth/services/onetap.service.d.ts +9 -0
- package/dist/auth/services/onetap.service.js +94 -0
- package/dist/auth/services/onetap.service.js.map +1 -0
- package/dist/auth/services/otp.service.d.ts +21 -0
- package/dist/auth/services/otp.service.js +152 -0
- package/dist/auth/services/otp.service.js.map +1 -0
- package/dist/auth/services/passkey.service.d.ts +40 -0
- package/dist/auth/services/passkey.service.js +132 -0
- package/dist/auth/services/passkey.service.js.map +1 -0
- package/dist/auth/services/sso.service.d.ts +18 -0
- package/dist/auth/services/sso.service.js +125 -0
- package/dist/auth/services/sso.service.js.map +1 -0
- package/dist/auth/services/token-blacklist.service.d.ts +9 -0
- package/dist/auth/services/token-blacklist.service.js +55 -0
- package/dist/auth/services/token-blacklist.service.js.map +1 -0
- package/dist/auth/services/token.service.d.ts +21 -0
- package/dist/auth/services/token.service.js +114 -0
- package/dist/auth/services/token.service.js.map +1 -0
- package/dist/auth/services/two-factor.service.d.ts +23 -0
- package/dist/auth/services/two-factor.service.js +144 -0
- package/dist/auth/services/two-factor.service.js.map +1 -0
- package/dist/auth/strategies/jwt.strategy.d.ts +17 -0
- package/dist/auth/strategies/jwt.strategy.js +39 -0
- package/dist/auth/strategies/jwt.strategy.js.map +1 -0
- package/dist/auth/types/request.type.d.ts +5 -0
- package/dist/auth/types/request.type.js +3 -0
- package/dist/auth/types/request.type.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/swagger/README.md +53 -0
- package/dist/swagger/index.d.ts +2 -0
- package/dist/swagger/index.js +6 -0
- package/dist/swagger/index.js.map +1 -0
- package/dist/swagger/swagger-setup.d.ts +3 -0
- package/dist/swagger/swagger-setup.js +21 -0
- package/dist/swagger/swagger-setup.js.map +1 -0
- package/dist/swagger/swagger.interfaces.d.ts +9 -0
- package/dist/swagger/swagger.interfaces.js +3 -0
- package/dist/swagger/swagger.interfaces.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +87 -5
- package/src/auth/README.md +346 -0
- package/src/swagger/README.md +53 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var AuthModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AuthModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
13
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
14
|
+
const user_entity_1 = require("./entities/user.entity");
|
|
15
|
+
const account_entity_1 = require("./entities/account.entity");
|
|
16
|
+
const verification_entity_1 = require("./entities/verification.entity");
|
|
17
|
+
const passkey_entity_1 = require("./entities/passkey.entity");
|
|
18
|
+
const token_session_entity_1 = require("./entities/token-session.entity");
|
|
19
|
+
const auth_constants_1 = require("./auth.constants");
|
|
20
|
+
const auth_service_1 = require("./services/auth.service");
|
|
21
|
+
const token_service_1 = require("./services/token.service");
|
|
22
|
+
const oauth_service_1 = require("./services/oauth.service");
|
|
23
|
+
const two_factor_service_1 = require("./services/two-factor.service");
|
|
24
|
+
const otp_service_1 = require("./services/otp.service");
|
|
25
|
+
const magic_link_service_1 = require("./services/magic-link.service");
|
|
26
|
+
const passkey_service_1 = require("./services/passkey.service");
|
|
27
|
+
const anonymous_service_1 = require("./services/anonymous.service");
|
|
28
|
+
const sso_service_1 = require("./services/sso.service");
|
|
29
|
+
const onetap_service_1 = require("./services/onetap.service");
|
|
30
|
+
const token_blacklist_service_1 = require("./services/token-blacklist.service");
|
|
31
|
+
const auth_controller_1 = require("./controllers/auth.controller");
|
|
32
|
+
const two_factor_controller_1 = require("./controllers/two-factor.controller");
|
|
33
|
+
const passkey_controller_1 = require("./controllers/passkey.controller");
|
|
34
|
+
const admin_controller_1 = require("./controllers/admin.controller");
|
|
35
|
+
const auth_guard_1 = require("./guards/auth.guard");
|
|
36
|
+
const roles_guard_1 = require("./guards/roles.guard");
|
|
37
|
+
const jwt_strategy_1 = require("./strategies/jwt.strategy");
|
|
38
|
+
const guards = [auth_guard_1.AuthGuard, roles_guard_1.RolesGuard];
|
|
39
|
+
const strategies = [jwt_strategy_1.JwtStrategy];
|
|
40
|
+
function buildDefaultOptions(options) {
|
|
41
|
+
return {
|
|
42
|
+
providers: options?.providers ?? ['credentials'],
|
|
43
|
+
credentials: {
|
|
44
|
+
enabled: options?.credentials?.enabled ?? true,
|
|
45
|
+
allowRegistration: options?.credentials?.allowRegistration ?? true,
|
|
46
|
+
},
|
|
47
|
+
oauth: options?.oauth,
|
|
48
|
+
sso: options?.sso,
|
|
49
|
+
twoFactor: {
|
|
50
|
+
enabled: options?.twoFactor?.enabled ?? true,
|
|
51
|
+
methods: options?.twoFactor?.methods ?? ['totp', 'email'],
|
|
52
|
+
issuer: options?.twoFactor?.issuer,
|
|
53
|
+
backupCodesCount: options?.twoFactor?.backupCodesCount ?? 8,
|
|
54
|
+
},
|
|
55
|
+
passkey: {
|
|
56
|
+
enabled: options?.passkey?.enabled ?? false,
|
|
57
|
+
relyingPartyName: options?.passkey?.relyingPartyName ?? 'NestHub Auth',
|
|
58
|
+
relyingPartyId: options?.passkey?.relyingPartyId,
|
|
59
|
+
origin: options?.passkey?.origin,
|
|
60
|
+
},
|
|
61
|
+
anonymous: {
|
|
62
|
+
enabled: options?.anonymous?.enabled ?? true,
|
|
63
|
+
maxAgeDays: options?.anonymous?.maxAgeDays ?? 30,
|
|
64
|
+
},
|
|
65
|
+
magicLink: {
|
|
66
|
+
enabled: options?.magicLink?.enabled ?? false,
|
|
67
|
+
expiresInMinutes: options?.magicLink?.expiresInMinutes ?? 15,
|
|
68
|
+
},
|
|
69
|
+
otp: {
|
|
70
|
+
enabled: options?.otp?.enabled ?? false,
|
|
71
|
+
expiresInMinutes: options?.otp?.expiresInMinutes ?? 10,
|
|
72
|
+
length: options?.otp?.length ?? 6,
|
|
73
|
+
},
|
|
74
|
+
onelink: {
|
|
75
|
+
enabled: options?.onelink?.enabled ?? false,
|
|
76
|
+
},
|
|
77
|
+
email: options?.email,
|
|
78
|
+
security: {
|
|
79
|
+
passwordHashRounds: options?.security?.passwordHashRounds ?? 12,
|
|
80
|
+
jwtSecret: options?.security?.jwtSecret,
|
|
81
|
+
jwtExpiresIn: options?.security?.jwtExpiresIn ?? '15m',
|
|
82
|
+
refreshTokenSecret: options?.security?.refreshTokenSecret,
|
|
83
|
+
refreshTokenExpiresIn: options?.security?.refreshTokenExpiresIn ?? '7d',
|
|
84
|
+
rateLimit: options?.security?.rateLimit ?? {
|
|
85
|
+
enabled: true,
|
|
86
|
+
maxAttempts: 5,
|
|
87
|
+
windowMs: 900000,
|
|
88
|
+
},
|
|
89
|
+
requireEmailVerification: options?.security?.requireEmailVerification ?? false,
|
|
90
|
+
maxSessions: options?.security?.maxSessions,
|
|
91
|
+
},
|
|
92
|
+
database: {
|
|
93
|
+
entities: options?.database?.entities,
|
|
94
|
+
},
|
|
95
|
+
cache: options?.cache,
|
|
96
|
+
override: options?.override,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function hasOAuth(opts) {
|
|
100
|
+
if (!opts.oauth)
|
|
101
|
+
return false;
|
|
102
|
+
return Object.values(opts.oauth).some((v) => v !== undefined && 'clientId' in v && v.enabled !== false);
|
|
103
|
+
}
|
|
104
|
+
function hasSSO(opts) {
|
|
105
|
+
return !!opts.sso && opts.sso.some((p) => p.enabled !== false);
|
|
106
|
+
}
|
|
107
|
+
function resolveConditionalServices(override, opts) {
|
|
108
|
+
const s = override?.services;
|
|
109
|
+
const services = [
|
|
110
|
+
s?.auth ?? auth_service_1.AuthService,
|
|
111
|
+
token_service_1.TokenService,
|
|
112
|
+
token_blacklist_service_1.TokenBlacklistService,
|
|
113
|
+
anonymous_service_1.AnonymousService,
|
|
114
|
+
];
|
|
115
|
+
if (hasOAuth(opts) || opts.onelink?.enabled || s?.oauth) {
|
|
116
|
+
services.push(s?.oauth ?? oauth_service_1.OAuthService);
|
|
117
|
+
}
|
|
118
|
+
if (opts.twoFactor?.enabled || s?.twoFactor) {
|
|
119
|
+
services.push(s?.twoFactor ?? two_factor_service_1.TwoFactorService);
|
|
120
|
+
}
|
|
121
|
+
if (opts.otp?.enabled || s?.otp) {
|
|
122
|
+
services.push(s?.otp ?? otp_service_1.OtpService);
|
|
123
|
+
}
|
|
124
|
+
if (opts.magicLink?.enabled || s?.magicLink) {
|
|
125
|
+
services.push(s?.magicLink ?? magic_link_service_1.MagicLinkService);
|
|
126
|
+
}
|
|
127
|
+
if (opts.passkey?.enabled || s?.passkey) {
|
|
128
|
+
services.push(s?.passkey ?? passkey_service_1.PasskeyService);
|
|
129
|
+
}
|
|
130
|
+
if (hasSSO(opts) || s?.sso) {
|
|
131
|
+
services.push(s?.sso ?? sso_service_1.SSOService);
|
|
132
|
+
}
|
|
133
|
+
if (opts.onelink?.enabled || s?.onetap) {
|
|
134
|
+
services.push(s?.onetap ?? onetap_service_1.OnetapService);
|
|
135
|
+
}
|
|
136
|
+
return services;
|
|
137
|
+
}
|
|
138
|
+
function resolveConditionalControllers(override, opts) {
|
|
139
|
+
const c = override?.controllers;
|
|
140
|
+
const controllers = [c?.auth ?? auth_controller_1.AuthController, admin_controller_1.AdminController];
|
|
141
|
+
if (opts.twoFactor?.enabled || c?.twoFactor) {
|
|
142
|
+
controllers.push(c?.twoFactor ?? two_factor_controller_1.TwoFactorController);
|
|
143
|
+
}
|
|
144
|
+
if (opts.passkey?.enabled || c?.passkey) {
|
|
145
|
+
controllers.push(c?.passkey ?? passkey_controller_1.PasskeyController);
|
|
146
|
+
}
|
|
147
|
+
return controllers;
|
|
148
|
+
}
|
|
149
|
+
function resolveConditionalEntities(override, opts) {
|
|
150
|
+
const e = override?.entities;
|
|
151
|
+
const entities = [e?.user ?? user_entity_1.User, token_session_entity_1.TokenSession];
|
|
152
|
+
if (hasOAuth(opts) ||
|
|
153
|
+
hasSSO(opts) ||
|
|
154
|
+
override?.services?.oauth ||
|
|
155
|
+
override?.services?.sso) {
|
|
156
|
+
entities.push(e?.account ?? account_entity_1.Account);
|
|
157
|
+
}
|
|
158
|
+
if (opts.otp?.enabled ||
|
|
159
|
+
opts.magicLink?.enabled ||
|
|
160
|
+
override?.services?.otp ||
|
|
161
|
+
override?.services?.magicLink) {
|
|
162
|
+
entities.push(e?.verification ?? verification_entity_1.Verification);
|
|
163
|
+
}
|
|
164
|
+
if (opts.passkey?.enabled || override?.services?.passkey) {
|
|
165
|
+
entities.push(e?.passkey ?? passkey_entity_1.Passkey);
|
|
166
|
+
}
|
|
167
|
+
return entities;
|
|
168
|
+
}
|
|
169
|
+
let AuthModule = AuthModule_1 = class AuthModule {
|
|
170
|
+
static forRoot(options) {
|
|
171
|
+
const resolvedOptions = buildDefaultOptions(options);
|
|
172
|
+
const jwtSecret = resolvedOptions.security?.jwtSecret ||
|
|
173
|
+
process.env.JWT_SECRET ||
|
|
174
|
+
'nesthub-jwt-secret';
|
|
175
|
+
const entities = resolveConditionalEntities(options?.override, resolvedOptions);
|
|
176
|
+
const services = resolveConditionalServices(options?.override, resolvedOptions);
|
|
177
|
+
const controllers = resolveConditionalControllers(options?.override, resolvedOptions);
|
|
178
|
+
return {
|
|
179
|
+
module: AuthModule_1,
|
|
180
|
+
imports: [
|
|
181
|
+
typeorm_1.TypeOrmModule.forFeature(entities),
|
|
182
|
+
jwt_1.JwtModule.register({
|
|
183
|
+
secret: jwtSecret,
|
|
184
|
+
signOptions: {
|
|
185
|
+
expiresIn: (resolvedOptions.security?.jwtExpiresIn ??
|
|
186
|
+
'15m'),
|
|
187
|
+
},
|
|
188
|
+
}),
|
|
189
|
+
],
|
|
190
|
+
controllers,
|
|
191
|
+
providers: [
|
|
192
|
+
...services,
|
|
193
|
+
...guards,
|
|
194
|
+
...strategies,
|
|
195
|
+
{
|
|
196
|
+
provide: auth_constants_1.AUTH_OPTIONS,
|
|
197
|
+
useValue: resolvedOptions,
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
exports: [...services, ...guards, AuthModule_1],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
static forRootAsync(options) {
|
|
204
|
+
const allEntities = [
|
|
205
|
+
user_entity_1.User,
|
|
206
|
+
account_entity_1.Account,
|
|
207
|
+
verification_entity_1.Verification,
|
|
208
|
+
passkey_entity_1.Passkey,
|
|
209
|
+
token_session_entity_1.TokenSession,
|
|
210
|
+
];
|
|
211
|
+
const allControllers = [
|
|
212
|
+
auth_controller_1.AuthController,
|
|
213
|
+
admin_controller_1.AdminController,
|
|
214
|
+
two_factor_controller_1.TwoFactorController,
|
|
215
|
+
passkey_controller_1.PasskeyController,
|
|
216
|
+
];
|
|
217
|
+
const allServices = [
|
|
218
|
+
auth_service_1.AuthService,
|
|
219
|
+
token_service_1.TokenService,
|
|
220
|
+
token_blacklist_service_1.TokenBlacklistService,
|
|
221
|
+
oauth_service_1.OAuthService,
|
|
222
|
+
two_factor_service_1.TwoFactorService,
|
|
223
|
+
otp_service_1.OtpService,
|
|
224
|
+
magic_link_service_1.MagicLinkService,
|
|
225
|
+
passkey_service_1.PasskeyService,
|
|
226
|
+
anonymous_service_1.AnonymousService,
|
|
227
|
+
sso_service_1.SSOService,
|
|
228
|
+
onetap_service_1.OnetapService,
|
|
229
|
+
];
|
|
230
|
+
return {
|
|
231
|
+
module: AuthModule_1,
|
|
232
|
+
imports: [
|
|
233
|
+
...(options.imports ?? []),
|
|
234
|
+
jwt_1.JwtModule.registerAsync({
|
|
235
|
+
global: true,
|
|
236
|
+
useFactory: async (...args) => {
|
|
237
|
+
const opts = await options.useFactory(...args);
|
|
238
|
+
return {
|
|
239
|
+
secret: opts.security?.jwtSecret ||
|
|
240
|
+
process.env.JWT_SECRET ||
|
|
241
|
+
'nesthub-jwt-secret',
|
|
242
|
+
signOptions: {
|
|
243
|
+
expiresIn: (opts.security?.jwtExpiresIn ??
|
|
244
|
+
'15m'),
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
},
|
|
248
|
+
inject: options.inject,
|
|
249
|
+
}),
|
|
250
|
+
typeorm_1.TypeOrmModule.forFeature(allEntities),
|
|
251
|
+
],
|
|
252
|
+
providers: [
|
|
253
|
+
...allServices,
|
|
254
|
+
...guards,
|
|
255
|
+
...strategies,
|
|
256
|
+
{
|
|
257
|
+
provide: auth_constants_1.AUTH_OPTIONS,
|
|
258
|
+
useFactory: async (...args) => {
|
|
259
|
+
const opts = await options.useFactory(...args);
|
|
260
|
+
return buildDefaultOptions(opts);
|
|
261
|
+
},
|
|
262
|
+
inject: options.inject,
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
controllers: allControllers,
|
|
266
|
+
exports: [...allServices, ...guards, AuthModule_1],
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
exports.AuthModule = AuthModule;
|
|
271
|
+
exports.AuthModule = AuthModule = AuthModule_1 = __decorate([
|
|
272
|
+
(0, common_1.Global)(),
|
|
273
|
+
(0, common_1.Module)({})
|
|
274
|
+
], AuthModule);
|
|
275
|
+
//# sourceMappingURL=auth.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../src/auth/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAMwB;AACxB,6CAAgD;AAChD,qCAAwC;AAExC,wDAA8C;AAC9C,8DAAoD;AACpD,wEAA8D;AAC9D,8DAAoD;AACpD,0EAA+D;AAC/D,qDAAgD;AAEhD,0DAAsD;AACtD,4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,13 @@
|
|
|
1
|
+
import { AnonymousService } from '../services/anonymous.service';
|
|
2
|
+
export declare class AdminController {
|
|
3
|
+
private readonly anonymousService;
|
|
4
|
+
constructor(anonymousService: AnonymousService);
|
|
5
|
+
getStats(): Promise<{
|
|
6
|
+
anonymousUsers: number;
|
|
7
|
+
}>;
|
|
8
|
+
cleanupAnonymous(input: {
|
|
9
|
+
maxAgeDays?: number;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
deleted: number;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AdminController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const auth_guard_1 = require("../guards/auth.guard");
|
|
18
|
+
const roles_guard_1 = require("../guards/roles.guard");
|
|
19
|
+
const roles_decorator_1 = require("../decorators/roles.decorator");
|
|
20
|
+
const anonymous_service_1 = require("../services/anonymous.service");
|
|
21
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
22
|
+
const responses_1 = require("../responses");
|
|
23
|
+
let AdminController = class AdminController {
|
|
24
|
+
anonymousService;
|
|
25
|
+
constructor(anonymousService) {
|
|
26
|
+
this.anonymousService = anonymousService;
|
|
27
|
+
}
|
|
28
|
+
async getStats() {
|
|
29
|
+
const anonymousCount = await this.anonymousService.getAnonymousUserCount();
|
|
30
|
+
return {
|
|
31
|
+
anonymousUsers: anonymousCount,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async cleanupAnonymous(input) {
|
|
35
|
+
const deleted = await this.anonymousService.cleanupExpiredAnonymousUsers(input.maxAgeDays);
|
|
36
|
+
return { deleted };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.AdminController = AdminController;
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, common_1.Get)('stats'),
|
|
42
|
+
(0, swagger_1.ApiOperation)({ summary: 'Get auth statistics (admin only)' }),
|
|
43
|
+
(0, swagger_1.ApiOkResponse)({ type: responses_1.AdminStatsResponse }),
|
|
44
|
+
__metadata("design:type", Function),
|
|
45
|
+
__metadata("design:paramtypes", []),
|
|
46
|
+
__metadata("design:returntype", Promise)
|
|
47
|
+
], AdminController.prototype, "getStats", null);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, common_1.Post)('cleanup-anonymous'),
|
|
50
|
+
(0, swagger_1.ApiOperation)({ summary: 'Cleanup expired anonymous users (admin only)' }),
|
|
51
|
+
(0, swagger_1.ApiBody)({
|
|
52
|
+
schema: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
maxAgeDays: { type: 'number', example: 30 },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
(0, swagger_1.ApiOkResponse)({ type: responses_1.AdminCleanupResponse }),
|
|
60
|
+
__param(0, (0, common_1.Body)()),
|
|
61
|
+
__metadata("design:type", Function),
|
|
62
|
+
__metadata("design:paramtypes", [Object]),
|
|
63
|
+
__metadata("design:returntype", Promise)
|
|
64
|
+
], AdminController.prototype, "cleanupAnonymous", null);
|
|
65
|
+
exports.AdminController = AdminController = __decorate([
|
|
66
|
+
(0, swagger_1.ApiTags)('Admin'),
|
|
67
|
+
(0, common_1.Controller)('auth/admin'),
|
|
68
|
+
(0, common_1.UseGuards)(auth_guard_1.AuthGuard, roles_guard_1.RolesGuard),
|
|
69
|
+
(0, roles_decorator_1.Roles)('admin'),
|
|
70
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
71
|
+
__metadata("design:paramtypes", [anonymous_service_1.AnonymousService])
|
|
72
|
+
], AdminController);
|
|
73
|
+
//# sourceMappingURL=admin.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.controller.js","sourceRoot":"","sources":["../../../src/auth/controllers/admin.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwE;AACxE,qDAAiD;AACjD,uDAAmD;AACnD,mEAAsD;AACtD,qEAAiE;AAEjE,6CAMyB;AACzB,4CAAwE;AAOjE,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;IAAG,CAAC;IAK7D,AAAN,KAAK,CAAC,QAAQ;QACZ,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,EAAE,CAAC;QAC3E,OAAO;YACL,cAAc,EAAE,cAAc;SAC/B,CAAC;IACJ,CAAC;IAaK,AAAN,KAAK,CAAC,gBAAgB,CACZ,KAA8B;QAEtC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,4BAA4B,CACtE,KAAK,CAAC,UAAU,CACjB,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,CAAC;IACrB,CAAC;CACF,CAAA;AAhCY,0CAAe;AAMpB;IAHL,IAAA,YAAG,EAAC,OAAO,CAAC;IACZ,IAAA,sBAAY,EAAC,EAAE,OAAO,EAAE,kCAAkC,EAAE,CAAC;IAC7D,IAAA,uBAAa,EAAC,EAAE,IAAI,EAAE,8BAAkB,EAAE,CAAC;;;;+CAM3C;AAaK;IAXL,IAAA,aAAI,EAAC,mBAAmB,CAAC;IACzB,IAAA,sBAAY,EAAC,EAAE,OAAO,EAAE,8CAA8C,EAAE,CAAC;IACzE,IAAA,iBAAO,EAAC;QACP,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;aAC5C;SACF;KACF,CAAC;IACD,IAAA,uBAAa,EAAC,EAAE,IAAI,EAAE,gCAAoB,EAAE,CAAC;IAE3C,WAAA,IAAA,aAAI,GAAE,CAAA;;;;uDAMR;0BA/BU,eAAe;IAL3B,IAAA,iBAAO,EAAC,OAAO,CAAC;IAChB,IAAA,mBAAU,EAAC,YAAY,CAAC;IACxB,IAAA,kBAAS,EAAC,sBAAS,EAAE,wBAAU,CAAC;IAChC,IAAA,uBAAK,EAAC,OAAO,CAAC;IACd,IAAA,uBAAa,GAAE;qCAEiC,oCAAgB;GADpD,eAAe,CAgC3B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AuthService } from '../services/auth.service';
|
|
2
|
+
import type { AuthRequest } from '../types/request.type';
|
|
3
|
+
import { RegisterDto, LoginDto, ChangePasswordDto, UpdateProfileDto, AuthResponseDto, ProfileDto, SessionDto, RevokeSessionDto, LogoutDto } from '../responses';
|
|
4
|
+
export declare class AuthController {
|
|
5
|
+
private readonly authService;
|
|
6
|
+
constructor(authService: AuthService);
|
|
7
|
+
register(body: RegisterDto, req: AuthRequest): Promise<AuthResponseDto>;
|
|
8
|
+
login(body: LoginDto, req: AuthRequest): Promise<AuthResponseDto>;
|
|
9
|
+
loginAnonymous(req: AuthRequest): Promise<AuthResponseDto>;
|
|
10
|
+
refresh(refreshToken: string, req: AuthRequest): Promise<AuthResponseDto>;
|
|
11
|
+
logout(req: AuthRequest, body?: LogoutDto): Promise<{
|
|
12
|
+
message: string;
|
|
13
|
+
}>;
|
|
14
|
+
logoutAll(req: AuthRequest): Promise<{
|
|
15
|
+
message: string;
|
|
16
|
+
}>;
|
|
17
|
+
getSessions(req: AuthRequest): Promise<SessionDto[]>;
|
|
18
|
+
revokeSession(req: AuthRequest, params: RevokeSessionDto): Promise<{
|
|
19
|
+
message: string;
|
|
20
|
+
}>;
|
|
21
|
+
getProfile(req: AuthRequest): Promise<ProfileDto>;
|
|
22
|
+
updateProfile(req: AuthRequest, body: UpdateProfileDto): Promise<ProfileDto>;
|
|
23
|
+
changePassword(req: AuthRequest, body: ChangePasswordDto): Promise<{
|
|
24
|
+
message: string;
|
|
25
|
+
}>;
|
|
26
|
+
deleteAccount(req: AuthRequest): Promise<{
|
|
27
|
+
message: string;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AuthController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
18
|
+
const auth_service_1 = require("../services/auth.service");
|
|
19
|
+
const auth_guard_1 = require("../guards/auth.guard");
|
|
20
|
+
const public_decorator_1 = require("../decorators/public.decorator");
|
|
21
|
+
const responses_1 = require("../responses");
|
|
22
|
+
function extractMetadata(req, deviceName) {
|
|
23
|
+
return {
|
|
24
|
+
ipAddress: req.ip ?? req.socket?.remoteAddress,
|
|
25
|
+
userAgent: req.headers?.['user-agent'],
|
|
26
|
+
deviceName,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
let AuthController = class AuthController {
|
|
30
|
+
authService;
|
|
31
|
+
constructor(authService) {
|
|
32
|
+
this.authService = authService;
|
|
33
|
+
}
|
|
34
|
+
async register(body, req) {
|
|
35
|
+
const result = await this.authService.register(body, extractMetadata(req, body.deviceName));
|
|
36
|
+
return {
|
|
37
|
+
user: result.user,
|
|
38
|
+
accessToken: result.accessToken,
|
|
39
|
+
refreshToken: result.refreshToken,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async login(body, req) {
|
|
43
|
+
const result = await this.authService.loginWithPassword(body.identifier, body.password, extractMetadata(req, body.deviceName));
|
|
44
|
+
if (result.requiresTwoFactor) {
|
|
45
|
+
return {
|
|
46
|
+
user: result.user,
|
|
47
|
+
requiresTwoFactor: true,
|
|
48
|
+
accessToken: '',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
user: result.user,
|
|
53
|
+
accessToken: result.accessToken,
|
|
54
|
+
refreshToken: result.refreshToken,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async loginAnonymous(req) {
|
|
58
|
+
const result = await this.authService.loginAnonymous(extractMetadata(req));
|
|
59
|
+
return {
|
|
60
|
+
user: result.user,
|
|
61
|
+
accessToken: result.accessToken,
|
|
62
|
+
refreshToken: result.refreshToken,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async refresh(refreshToken, req) {
|
|
66
|
+
const result = await this.authService.refreshAccessToken(refreshToken, extractMetadata(req));
|
|
67
|
+
if (!result) {
|
|
68
|
+
return {
|
|
69
|
+
user: {},
|
|
70
|
+
accessToken: '',
|
|
71
|
+
error: 'Invalid refresh token',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
user: result.user,
|
|
76
|
+
accessToken: result.accessToken,
|
|
77
|
+
refreshToken: result.refreshToken,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async logout(req, body) {
|
|
81
|
+
await this.authService.logout(req.user.id, body?.jti);
|
|
82
|
+
return { message: 'Logged out successfully' };
|
|
83
|
+
}
|
|
84
|
+
async logoutAll(req) {
|
|
85
|
+
await this.authService.logoutAll(req.user.id);
|
|
86
|
+
return { message: 'All sessions logged out' };
|
|
87
|
+
}
|
|
88
|
+
async getSessions(req) {
|
|
89
|
+
return this.authService.getUserSessions(req.user.id);
|
|
90
|
+
}
|
|
91
|
+
async revokeSession(req, params) {
|
|
92
|
+
await this.authService.revokeSession(params.id, req.user.id);
|
|
93
|
+
return { message: 'Session revoked' };
|
|
94
|
+
}
|
|
95
|
+
async getProfile(req) {
|
|
96
|
+
const profile = await this.authService.getProfile(req.user.id);
|
|
97
|
+
return profile;
|
|
98
|
+
}
|
|
99
|
+
async updateProfile(req, body) {
|
|
100
|
+
const result = await this.authService.updateProfile(req.user.id, body);
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
async changePassword(req, body) {
|
|
104
|
+
await this.authService.changePassword(req.user.id, body.currentPassword, body.newPassword);
|
|
105
|
+
return { message: 'Password changed successfully' };
|
|
106
|
+
}
|
|
107
|
+
async deleteAccount(req) {
|
|
108
|
+
await this.authService.deleteAccount(req.user.id);
|
|
109
|
+
return { message: 'Account deleted successfully' };
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
exports.AuthController = AuthController;
|
|
113
|
+
__decorate([
|
|
114
|
+
(0, public_decorator_1.Public)(),
|
|
115
|
+
(0, common_1.Post)('register'),
|
|
116
|
+
(0, swagger_1.ApiOperation)({ summary: 'Register new user' }),
|
|
117
|
+
(0, swagger_1.ApiBody)({ type: responses_1.RegisterDto }),
|
|
118
|
+
__param(0, (0, common_1.Body)()),
|
|
119
|
+
__param(1, (0, common_1.Req)()),
|
|
120
|
+
__metadata("design:type", Function),
|
|
121
|
+
__metadata("design:paramtypes", [responses_1.RegisterDto, Object]),
|
|
122
|
+
__metadata("design:returntype", Promise)
|
|
123
|
+
], AuthController.prototype, "register", null);
|
|
124
|
+
__decorate([
|
|
125
|
+
(0, public_decorator_1.Public)(),
|
|
126
|
+
(0, common_1.Post)('login'),
|
|
127
|
+
(0, swagger_1.ApiOperation)({ summary: 'Login with email/phone and password' }),
|
|
128
|
+
(0, swagger_1.ApiBody)({ type: responses_1.LoginDto }),
|
|
129
|
+
__param(0, (0, common_1.Body)()),
|
|
130
|
+
__param(1, (0, common_1.Req)()),
|
|
131
|
+
__metadata("design:type", Function),
|
|
132
|
+
__metadata("design:paramtypes", [responses_1.LoginDto, Object]),
|
|
133
|
+
__metadata("design:returntype", Promise)
|
|
134
|
+
], AuthController.prototype, "login", null);
|
|
135
|
+
__decorate([
|
|
136
|
+
(0, public_decorator_1.Public)(),
|
|
137
|
+
(0, common_1.Post)('anonymous'),
|
|
138
|
+
(0, swagger_1.ApiOperation)({ summary: 'Login anonymously' }),
|
|
139
|
+
__param(0, (0, common_1.Req)()),
|
|
140
|
+
__metadata("design:type", Function),
|
|
141
|
+
__metadata("design:paramtypes", [Object]),
|
|
142
|
+
__metadata("design:returntype", Promise)
|
|
143
|
+
], AuthController.prototype, "loginAnonymous", null);
|
|
144
|
+
__decorate([
|
|
145
|
+
(0, public_decorator_1.Public)(),
|
|
146
|
+
(0, common_1.Post)('refresh'),
|
|
147
|
+
(0, swagger_1.ApiOperation)({ summary: 'Refresh access token' }),
|
|
148
|
+
(0, swagger_1.ApiBody)({
|
|
149
|
+
schema: {
|
|
150
|
+
properties: {
|
|
151
|
+
refreshToken: {
|
|
152
|
+
type: 'string',
|
|
153
|
+
example: 'dGhpcyBpcyBhIHJlZnJlc2ggdG9rZW4uLi4=',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
}),
|
|
158
|
+
__param(0, (0, common_1.Body)('refreshToken')),
|
|
159
|
+
__param(1, (0, common_1.Req)()),
|
|
160
|
+
__metadata("design:type", Function),
|
|
161
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
162
|
+
__metadata("design:returntype", Promise)
|
|
163
|
+
], AuthController.prototype, "refresh", null);
|
|
164
|
+
__decorate([
|
|
165
|
+
(0, common_1.UseGuards)(auth_guard_1.AuthGuard),
|
|
166
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
167
|
+
(0, common_1.Post)('logout'),
|
|
168
|
+
(0, swagger_1.ApiOperation)({ summary: 'Logout current session' }),
|
|
169
|
+
(0, swagger_1.ApiBody)({ type: responses_1.LogoutDto, required: false }),
|
|
170
|
+
__param(0, (0, common_1.Req)()),
|
|
171
|
+
__param(1, (0, common_1.Body)()),
|
|
172
|
+
__metadata("design:type", Function),
|
|
173
|
+
__metadata("design:paramtypes", [Object, responses_1.LogoutDto]),
|
|
174
|
+
__metadata("design:returntype", Promise)
|
|
175
|
+
], AuthController.prototype, "logout", null);
|
|
176
|
+
__decorate([
|
|
177
|
+
(0, common_1.UseGuards)(auth_guard_1.AuthGuard),
|
|
178
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
179
|
+
(0, common_1.Post)('logout-all'),
|
|
180
|
+
(0, swagger_1.ApiOperation)({ summary: 'Logout all sessions' }),
|
|
181
|
+
__param(0, (0, common_1.Req)()),
|
|
182
|
+
__metadata("design:type", Function),
|
|
183
|
+
__metadata("design:paramtypes", [Object]),
|
|
184
|
+
__metadata("design:returntype", Promise)
|
|
185
|
+
], AuthController.prototype, "logoutAll", null);
|
|
186
|
+
__decorate([
|
|
187
|
+
(0, common_1.UseGuards)(auth_guard_1.AuthGuard),
|
|
188
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
189
|
+
(0, common_1.Get)('sessions'),
|
|
190
|
+
(0, swagger_1.ApiOperation)({ summary: 'Get all active sessions with device info' }),
|
|
191
|
+
__param(0, (0, common_1.Req)()),
|
|
192
|
+
__metadata("design:type", Function),
|
|
193
|
+
__metadata("design:paramtypes", [Object]),
|
|
194
|
+
__metadata("design:returntype", Promise)
|
|
195
|
+
], AuthController.prototype, "getSessions", null);
|
|
196
|
+
__decorate([
|
|
197
|
+
(0, common_1.UseGuards)(auth_guard_1.AuthGuard),
|
|
198
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
199
|
+
(0, common_1.Delete)('sessions/:id'),
|
|
200
|
+
(0, swagger_1.ApiOperation)({ summary: 'Revoke a specific session (logout device)' }),
|
|
201
|
+
__param(0, (0, common_1.Req)()),
|
|
202
|
+
__param(1, (0, common_1.Param)()),
|
|
203
|
+
__metadata("design:type", Function),
|
|
204
|
+
__metadata("design:paramtypes", [Object, responses_1.RevokeSessionDto]),
|
|
205
|
+
__metadata("design:returntype", Promise)
|
|
206
|
+
], AuthController.prototype, "revokeSession", null);
|
|
207
|
+
__decorate([
|
|
208
|
+
(0, common_1.UseGuards)(auth_guard_1.AuthGuard),
|
|
209
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
210
|
+
(0, common_1.Get)('profile'),
|
|
211
|
+
(0, swagger_1.ApiOperation)({ summary: 'Get current user profile' }),
|
|
212
|
+
__param(0, (0, common_1.Req)()),
|
|
213
|
+
__metadata("design:type", Function),
|
|
214
|
+
__metadata("design:paramtypes", [Object]),
|
|
215
|
+
__metadata("design:returntype", Promise)
|
|
216
|
+
], AuthController.prototype, "getProfile", null);
|
|
217
|
+
__decorate([
|
|
218
|
+
(0, common_1.UseGuards)(auth_guard_1.AuthGuard),
|
|
219
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
220
|
+
(0, common_1.Patch)('profile'),
|
|
221
|
+
(0, swagger_1.ApiOperation)({ summary: 'Update profile' }),
|
|
222
|
+
(0, swagger_1.ApiBody)({ type: responses_1.UpdateProfileDto }),
|
|
223
|
+
__param(0, (0, common_1.Req)()),
|
|
224
|
+
__param(1, (0, common_1.Body)()),
|
|
225
|
+
__metadata("design:type", Function),
|
|
226
|
+
__metadata("design:paramtypes", [Object, responses_1.UpdateProfileDto]),
|
|
227
|
+
__metadata("design:returntype", Promise)
|
|
228
|
+
], AuthController.prototype, "updateProfile", null);
|
|
229
|
+
__decorate([
|
|
230
|
+
(0, common_1.UseGuards)(auth_guard_1.AuthGuard),
|
|
231
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
232
|
+
(0, common_1.Post)('change-password'),
|
|
233
|
+
(0, swagger_1.ApiOperation)({ summary: 'Change password' }),
|
|
234
|
+
(0, swagger_1.ApiBody)({ type: responses_1.ChangePasswordDto }),
|
|
235
|
+
__param(0, (0, common_1.Req)()),
|
|
236
|
+
__param(1, (0, common_1.Body)()),
|
|
237
|
+
__metadata("design:type", Function),
|
|
238
|
+
__metadata("design:paramtypes", [Object, responses_1.ChangePasswordDto]),
|
|
239
|
+
__metadata("design:returntype", Promise)
|
|
240
|
+
], AuthController.prototype, "changePassword", null);
|
|
241
|
+
__decorate([
|
|
242
|
+
(0, common_1.UseGuards)(auth_guard_1.AuthGuard),
|
|
243
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
244
|
+
(0, common_1.Delete)('account'),
|
|
245
|
+
(0, swagger_1.ApiOperation)({
|
|
246
|
+
summary: 'Delete account (GDPR) — anonymizes PII and invalidates all sessions',
|
|
247
|
+
}),
|
|
248
|
+
__param(0, (0, common_1.Req)()),
|
|
249
|
+
__metadata("design:type", Function),
|
|
250
|
+
__metadata("design:paramtypes", [Object]),
|
|
251
|
+
__metadata("design:returntype", Promise)
|
|
252
|
+
], AuthController.prototype, "deleteAccount", null);
|
|
253
|
+
exports.AuthController = AuthController = __decorate([
|
|
254
|
+
(0, swagger_1.ApiTags)('Auth'),
|
|
255
|
+
(0, common_1.Controller)('auth'),
|
|
256
|
+
__metadata("design:paramtypes", [auth_service_1.AuthService])
|
|
257
|
+
], AuthController);
|
|
258
|
+
//# sourceMappingURL=auth.controller.js.map
|