@hedhog/admin 0.46.1 → 0.46.3
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/dist/auth/auth.controller.d.ts +16 -3
- package/dist/auth/auth.controller.d.ts.map +1 -1
- package/dist/auth/auth.controller.js +15 -3
- package/dist/auth/auth.controller.js.map +1 -1
- package/dist/auth/auth.service.d.ts +14 -1
- package/dist/auth/auth.service.d.ts.map +1 -1
- package/dist/auth/auth.service.js +22 -2
- package/dist/auth/auth.service.js.map +1 -1
- package/dist/auth/dto/signup.dto.d.ts +6 -0
- package/dist/auth/dto/signup.dto.d.ts.map +1 -0
- package/dist/auth/dto/signup.dto.js +8 -0
- package/dist/auth/dto/signup.dto.js.map +1 -0
- package/dist/auth/guards/auth.guard.d.ts.map +1 -1
- package/dist/auth/guards/auth.guard.js +16 -9
- package/dist/auth/guards/auth.guard.js.map +1 -1
- package/package.json +43 -43
- package/src/auth/auth.controller.ts +22 -16
- package/src/auth/auth.service.ts +40 -14
- package/src/auth/dto/signup.dto.ts +6 -0
- package/src/auth/guards/auth.guard.ts +11 -7
@@ -1,13 +1,23 @@
|
|
1
1
|
import { AuthService } from './auth.service';
|
2
2
|
import { ForgetDTO } from './dto/forget.dto';
|
3
|
-
import { ResetDTO } from './dto/reset.dto';
|
4
3
|
import { LoginDTO } from './dto/login.dto';
|
5
4
|
import { OtpDTO } from './dto/otp.dto';
|
5
|
+
import { ResetDTO } from './dto/reset.dto';
|
6
|
+
import { SignupDTO } from './dto/signup.dto';
|
6
7
|
import { User as UserType } from './types/user.type';
|
7
8
|
export declare class AuthController {
|
8
9
|
private readonly service;
|
9
10
|
constructor(service: AuthService);
|
10
|
-
verify({ id }: UserType): Promise<
|
11
|
+
verify({ id }: UserType): Promise<{
|
12
|
+
code: string | null;
|
13
|
+
name: string;
|
14
|
+
id: number;
|
15
|
+
created_at: Date;
|
16
|
+
updated_at: Date;
|
17
|
+
multifactor_id: number | null;
|
18
|
+
email: string;
|
19
|
+
password: string;
|
20
|
+
}>;
|
11
21
|
login({ email, password }: LoginDTO): Promise<{
|
12
22
|
token: string;
|
13
23
|
} | {
|
@@ -21,7 +31,10 @@ export declare class AuthController {
|
|
21
31
|
subject: string;
|
22
32
|
body: string;
|
23
33
|
}): Promise<boolean>;
|
24
|
-
reset({ newPassword, confirmNewPassword, code
|
34
|
+
reset({ newPassword, confirmNewPassword, code }: ResetDTO): Promise<false | {
|
35
|
+
token: string;
|
36
|
+
}>;
|
37
|
+
signup({ fullName, cpf, email, password }: SignupDTO): Promise<{
|
25
38
|
token: string;
|
26
39
|
}>;
|
27
40
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAErD,qBACa,cAAc;IAGvB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,WAAW;IAKjC,MAAM,CAAS,EAAE,EAAE,EAAE,EAAE,QAAQ;;;;;;;;;;IAM/B,KAAK,CAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,QAAQ;;;;;;IAM3C,GAAG,CAAS,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,MAAM;;;IAMnC,MAAM,CAEV,EACE,KAAK,EACL,OAAO,EACP,IAAI,GACL,EAAE,SAAS,GAAG;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd;IAWG,KAAK,CAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,IAAI,EAAE,EAAE,QAAQ;;;IAUjE,MAAM,CAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,SAAS;;;CAGnE"}
|
@@ -13,12 +13,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
15
|
exports.AuthController = void 0;
|
16
|
-
const common_1 = require("@nestjs/common");
|
17
16
|
const core_1 = require("@hedhog/core");
|
17
|
+
const common_1 = require("@nestjs/common");
|
18
18
|
const auth_service_1 = require("./auth.service");
|
19
|
-
const reset_dto_1 = require("./dto/reset.dto");
|
20
19
|
const login_dto_1 = require("./dto/login.dto");
|
21
20
|
const otp_dto_1 = require("./dto/otp.dto");
|
21
|
+
const reset_dto_1 = require("./dto/reset.dto");
|
22
|
+
const signup_dto_1 = require("./dto/signup.dto");
|
22
23
|
let AuthController = class AuthController {
|
23
24
|
constructor(service) {
|
24
25
|
this.service = service;
|
@@ -39,13 +40,16 @@ let AuthController = class AuthController {
|
|
39
40
|
body,
|
40
41
|
});
|
41
42
|
}
|
42
|
-
async reset({ newPassword, confirmNewPassword, code
|
43
|
+
async reset({ newPassword, confirmNewPassword, code }) {
|
43
44
|
return this.service.resetPassword({
|
44
45
|
newPassword,
|
45
46
|
confirmNewPassword,
|
46
47
|
code,
|
47
48
|
});
|
48
49
|
}
|
50
|
+
async signup({ fullName, cpf, email, password }) {
|
51
|
+
return this.service.signup({ fullName, cpf, email, password });
|
52
|
+
}
|
49
53
|
};
|
50
54
|
exports.AuthController = AuthController;
|
51
55
|
__decorate([
|
@@ -88,6 +92,14 @@ __decorate([
|
|
88
92
|
__metadata("design:paramtypes", [reset_dto_1.ResetDTO]),
|
89
93
|
__metadata("design:returntype", Promise)
|
90
94
|
], AuthController.prototype, "reset", null);
|
95
|
+
__decorate([
|
96
|
+
(0, core_1.Public)(),
|
97
|
+
(0, common_1.Post)('signup'),
|
98
|
+
__param(0, (0, common_1.Body)()),
|
99
|
+
__metadata("design:type", Function),
|
100
|
+
__metadata("design:paramtypes", [signup_dto_1.SignupDTO]),
|
101
|
+
__metadata("design:returntype", Promise)
|
102
|
+
], AuthController.prototype, "signup", null);
|
91
103
|
exports.AuthController = AuthController = __decorate([
|
92
104
|
(0, common_1.Controller)('auth'),
|
93
105
|
__param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => auth_service_1.AuthService))),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAOwB;AACxB,
|
1
|
+
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAkD;AAClD,2CAOwB;AACxB,iDAA6C;AAE7C,+CAA2C;AAC3C,2CAAuC;AACvC,+CAA2C;AAC3C,iDAA6C;AAItC,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAEmB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IACpC,CAAC;IAIE,AAAN,KAAK,CAAC,MAAM,CAAS,EAAE,EAAE,EAAY;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,M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AAQ;;2CAEhD;AAIK;IAFL,IAAA,aAAM,GAAE;IACR,IAAA,aAAI,EAAC,KAAK,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAkB,gBAAM;;yCAExC;AAIK;IAFL,IAAA,aAAM,GAAE;IACR,IAAA,aAAI,EAAC,QAAQ,CAAC;IAEZ,WAAA,IAAA,aAAI,GAAE,CAAA;;;;4CAeR;AAIK;IAFL,IAAA,aAAM,GAAE;IACR,IAAA,aAAI,EAAC,OAAO,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAA4C,oBAAQ;;2CAMtE;AAIK;IAFL,IAAA,aAAM,GAAE;IACR,IAAA,aAAI,EAAC,QAAQ,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAqC,sBAAS;;4CAEjE;yBA1DU,cAAc;IAD1B,IAAA,mBAAU,EAAC,MAAM,CAAC;IAGd,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,0BAAW,CAAC,CAAC,CAAA;qCACZ,0BAAW;GAH5B,cAAc,CA2D1B"}
|
@@ -4,6 +4,7 @@ import { JwtService } from '@nestjs/jwt';
|
|
4
4
|
import { ForgetDTO } from './dto/forget.dto';
|
5
5
|
import { LoginDTO } from './dto/login.dto';
|
6
6
|
import { OtpDTO } from './dto/otp.dto';
|
7
|
+
import { SignupDTO } from './dto/signup.dto';
|
7
8
|
export declare class AuthService {
|
8
9
|
private readonly prisma;
|
9
10
|
private readonly jwt;
|
@@ -41,6 +42,18 @@ export declare class AuthService {
|
|
41
42
|
token: string;
|
42
43
|
mfa: boolean;
|
43
44
|
}>;
|
44
|
-
verify(id: number):
|
45
|
+
verify(id: number): import(".prisma/client").Prisma.Prisma__userClient<{
|
46
|
+
code: string | null;
|
47
|
+
name: string;
|
48
|
+
id: number;
|
49
|
+
created_at: Date;
|
50
|
+
updated_at: Date;
|
51
|
+
multifactor_id: number | null;
|
52
|
+
email: string;
|
53
|
+
password: string;
|
54
|
+
}, null, import("@prisma/client/runtime/library").DefaultArgs>;
|
55
|
+
signup({ fullName, cpf, email, password }: SignupDTO): Promise<{
|
56
|
+
token: string;
|
57
|
+
}>;
|
45
58
|
}
|
46
59
|
//# sourceMappingURL=auth.service.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQ/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQ/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,qBACa,WAAW;IAGpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAEpB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAJJ,MAAM,EAAE,aAAa,EAErB,GAAG,EAAE,UAAU,EAEf,IAAI,EAAE,WAAW;IAG9B,WAAW,CAAC,KAAK,EAAE,MAAM;IAM/B,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAW5C,oBAAoB,IAAI,MAAM;IAMxB,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;;;;;;IAgDzD,QAAQ,CAAC,IAAI,KAAA;;;IAUb,MAAM,CAAC,EACX,KAAK,EACL,OAAO,EACP,IAAI,GACL,EAAE,SAAS,GAAG;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf;IAwCK,aAAa,CAAC,EAClB,IAAI,EACJ,WAAW,EACX,kBAAkB,GACnB,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,kBAAkB,EAAE,MAAM,CAAC;KAC5B;;;IAkCK,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,MAAM;;;IA0BjC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,QAAQ;;;;;;IAInC,MAAM,CAAC,EAAE,EAAE,MAAM;;;;;;;;;;IAIX,MAAM,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,SAAS;;;CAwB3D"}
|
@@ -18,9 +18,9 @@ const prisma_1 = require("@hedhog/prisma");
|
|
18
18
|
const common_1 = require("@nestjs/common");
|
19
19
|
const jwt_1 = require("@nestjs/jwt");
|
20
20
|
const bcrypt_1 = require("bcrypt");
|
21
|
-
const multifactor_type_enum_1 = require("./enums/multifactor-type.enum");
|
22
|
-
const subject_1 = require("./consts/subject");
|
23
21
|
const body_1 = require("./consts/body");
|
22
|
+
const subject_1 = require("./consts/subject");
|
23
|
+
const multifactor_type_enum_1 = require("./enums/multifactor-type.enum");
|
24
24
|
let AuthService = class AuthService {
|
25
25
|
constructor(prisma, jwt, mail) {
|
26
26
|
this.prisma = prisma;
|
@@ -178,6 +178,26 @@ let AuthService = class AuthService {
|
|
178
178
|
verify(id) {
|
179
179
|
return this.prisma.user.findUnique({ where: { id } });
|
180
180
|
}
|
181
|
+
async signup({ fullName, cpf, email, password }) {
|
182
|
+
const existingUser = await this.prisma.user.findFirst({
|
183
|
+
where: {
|
184
|
+
OR: [{ email }],
|
185
|
+
},
|
186
|
+
});
|
187
|
+
if (existingUser) {
|
188
|
+
throw new common_1.BadRequestException('User already exists.');
|
189
|
+
}
|
190
|
+
const salt = await (0, bcrypt_1.genSalt)();
|
191
|
+
const hashedPassword = await (0, bcrypt_1.hash)(password, salt);
|
192
|
+
const user = await this.prisma.user.create({
|
193
|
+
data: {
|
194
|
+
email,
|
195
|
+
password: hashedPassword,
|
196
|
+
name: fullName,
|
197
|
+
},
|
198
|
+
});
|
199
|
+
return this.getToken(user);
|
200
|
+
}
|
181
201
|
};
|
182
202
|
exports.AuthService = AuthService;
|
183
203
|
exports.AuthService = AuthService = __decorate([
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAA2C;AAC3C,2CAA+C;AAC/C,2CAMwB;AACxB,qCAAyC;AACzC,mCAAgD;
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAA2C;AAC3C,2CAA+C;AAC/C,2CAMwB;AACxB,qCAAyC;AACzC,mCAAgD;AAEhD,wCAAwC;AACxC,8CAAoD;AAKpD,yEAAgE;AAGzD,IAAM,WAAW,GAAjB,MAAM,WAAW;IACtB,YAEmB,MAAqB,EAErB,GAAe,EAEf,IAAiB;QAJjB,WAAM,GAAN,MAAM,CAAe;QAErB,QAAG,GAAH,GAAG,CAAY;QAEf,SAAI,GAAJ,IAAI,CAAa;IACjC,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,KAAa;QAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE;YACjC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;SACvC,CAAC,CAAC;I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B"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"signup.dto.d.ts","sourceRoot":"","sources":["../../../src/auth/dto/signup.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,qBAAa,SAAU,SAAQ,QAAQ;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SignupDTO = void 0;
|
4
|
+
const login_dto_1 = require("./login.dto");
|
5
|
+
class SignupDTO extends login_dto_1.LoginDTO {
|
6
|
+
}
|
7
|
+
exports.SignupDTO = SignupDTO;
|
8
|
+
//# sourceMappingURL=signup.dto.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"signup.dto.js","sourceRoot":"","sources":["../../../src/auth/dto/signup.dto.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AAEvC,MAAa,SAAU,SAAQ,oBAAQ;CAGtC;AAHD,8BAGC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auth.guard.d.ts","sourceRoot":"","sources":["../../../src/auth/guards/auth.guard.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"auth.guard.d.ts","sourceRoot":"","sources":["../../../src/auth/guards/auth.guard.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,qBACa,SAAU,YAAW,WAAW;IAEzC,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,SAAS;gBADT,IAAI,EAAE,WAAW,EACjB,SAAS,EAAE,SAAS;IAGxB,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IA8B9D,OAAO,CAAC,sBAAsB;CAK/B"}
|
@@ -10,34 +10,41 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.AuthGuard = void 0;
|
13
|
+
const core_1 = require("@hedhog/core");
|
13
14
|
const common_1 = require("@nestjs/common");
|
14
|
-
const
|
15
|
+
const core_2 = require("@nestjs/core");
|
15
16
|
const auth_service_1 = require("../auth.service");
|
16
|
-
const core_2 = require("@hedhog/core");
|
17
17
|
let AuthGuard = class AuthGuard {
|
18
18
|
constructor(auth, reflector) {
|
19
19
|
this.auth = auth;
|
20
20
|
this.reflector = reflector;
|
21
21
|
}
|
22
22
|
async canActivate(context) {
|
23
|
-
const isPublic = this.reflector.getAllAndOverride(
|
23
|
+
const isPublic = this.reflector.getAllAndOverride(core_1.IS_PUBLIC_KEY, [
|
24
24
|
context.getHandler(),
|
25
25
|
context.getClass(),
|
26
26
|
]);
|
27
|
-
if (isPublic) {
|
28
|
-
return true;
|
29
|
-
}
|
30
27
|
const request = context.switchToHttp().getRequest();
|
31
28
|
const token = this.extractTokenFromHeader(request);
|
32
29
|
if (!token) {
|
33
|
-
|
30
|
+
if (isPublic) {
|
31
|
+
return true;
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
throw new common_1.UnauthorizedException();
|
35
|
+
}
|
34
36
|
}
|
35
37
|
try {
|
36
38
|
const payload = await this.auth.verifyToken(token);
|
37
39
|
request['auth'] = payload;
|
38
40
|
}
|
39
41
|
catch (error) {
|
40
|
-
|
42
|
+
if (isPublic) {
|
43
|
+
return true;
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
throw new common_1.UnauthorizedException(error);
|
47
|
+
}
|
41
48
|
}
|
42
49
|
return true;
|
43
50
|
}
|
@@ -51,6 +58,6 @@ exports.AuthGuard = AuthGuard;
|
|
51
58
|
exports.AuthGuard = AuthGuard = __decorate([
|
52
59
|
(0, common_1.Injectable)(),
|
53
60
|
__metadata("design:paramtypes", [auth_service_1.AuthService,
|
54
|
-
|
61
|
+
core_2.Reflector])
|
55
62
|
], AuthGuard);
|
56
63
|
//# sourceMappingURL=auth.guard.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auth.guard.js","sourceRoot":"","sources":["../../../src/auth/guards/auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,uCAAyC;AAEzC,kDAA8C;
|
1
|
+
{"version":3,"file":"auth.guard.js","sourceRoot":"","sources":["../../../src/auth/guards/auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA6C;AAC7C,2CAKwB;AACxB,uCAAyC;AAEzC,kDAA8C;AAGvC,IAAM,SAAS,GAAf,MAAM,SAAS;IACpB,YACU,IAAiB,EACjB,SAAoB;QADpB,SAAI,GAAJ,IAAI,CAAa;QACjB,cAAS,GAAT,SAAS,CAAW;IAC3B,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAU,oBAAa,EAAE;YACxE,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;QAEnD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,IAAI,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,8BAAqB,EAAE,CAAC;YACpC,CAAC;QACH,CAAC;QACD,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAEnD,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,IAAI,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,8BAAqB,CAAC,KAAK,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,sBAAsB,CAAC,OAAgB;;QAC7C,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,aAAa,0CAAE,KAAK,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC;QAEtE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;CACF,CAAA;AAzCY,8BAAS;oBAAT,SAAS;IADrB,IAAA,mBAAU,GAAE;qCAGK,0BAAW;QACN,gBAAS;GAHnB,SAAS,CAyCrB"}
|
package/package.json
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
{
|
2
|
-
"name": "@hedhog/admin",
|
3
|
-
"version": "0.46.
|
4
|
-
"private": false,
|
5
|
-
"main": "dist/index.js",
|
6
|
-
"scripts": {
|
7
|
-
"clean": "rimraf ./dist",
|
8
|
-
"prebuild": "npm run clean",
|
9
|
-
"build": "tsc --project tsconfig.production.json && npm version patch",
|
10
|
-
"prod": "npm run build && npm publish --access public"
|
11
|
-
},
|
12
|
-
"file": [
|
13
|
-
"dist/**/*",
|
14
|
-
"src/entities/**/*.ts",
|
15
|
-
"src/migrations/**/*.ts",
|
16
|
-
"src/**/*.ejs",
|
17
|
-
"hedhog.yaml"
|
18
|
-
],
|
19
|
-
"keywords": [],
|
20
|
-
"author": "",
|
21
|
-
"license": "MIT",
|
22
|
-
"description": "",
|
23
|
-
"dependencies": {
|
24
|
-
"@hedhog/mail": "^0.36.1"
|
25
|
-
},
|
26
|
-
"devDependencies": {
|
27
|
-
"@hedhog/locale": "^0.36.1",
|
28
|
-
"@hedhog/pagination": "^0.36.1",
|
29
|
-
"@hedhog/prisma": "^0.36.1",
|
30
|
-
"@hedhog/utils": "^0.0.28",
|
31
|
-
"@nestjs/mapped-types": "^2.0.5",
|
32
|
-
"ts-node": "^10.9.1",
|
33
|
-
"typescript": "^5.1.3"
|
34
|
-
},
|
35
|
-
"peerDependencies": {
|
36
|
-
"@hedhog/locale": "latest",
|
37
|
-
"@hedhog/mail": "latest",
|
38
|
-
"@hedhog/pagination": "latest",
|
39
|
-
"@hedhog/prisma": "latest",
|
40
|
-
"@hedhog/utils": "latest",
|
41
|
-
"@nestjs/jwt": "latest"
|
42
|
-
}
|
43
|
-
}
|
1
|
+
{
|
2
|
+
"name": "@hedhog/admin",
|
3
|
+
"version": "0.46.3",
|
4
|
+
"private": false,
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"scripts": {
|
7
|
+
"clean": "rimraf ./dist",
|
8
|
+
"prebuild": "npm run clean",
|
9
|
+
"build": "tsc --project tsconfig.production.json && npm version patch",
|
10
|
+
"prod": "npm run build && npm publish --access public"
|
11
|
+
},
|
12
|
+
"file": [
|
13
|
+
"dist/**/*",
|
14
|
+
"src/entities/**/*.ts",
|
15
|
+
"src/migrations/**/*.ts",
|
16
|
+
"src/**/*.ejs",
|
17
|
+
"hedhog.yaml"
|
18
|
+
],
|
19
|
+
"keywords": [],
|
20
|
+
"author": "",
|
21
|
+
"license": "MIT",
|
22
|
+
"description": "",
|
23
|
+
"dependencies": {
|
24
|
+
"@hedhog/mail": "^0.36.1"
|
25
|
+
},
|
26
|
+
"devDependencies": {
|
27
|
+
"@hedhog/locale": "^0.36.1",
|
28
|
+
"@hedhog/pagination": "^0.36.1",
|
29
|
+
"@hedhog/prisma": "^0.36.1",
|
30
|
+
"@hedhog/utils": "^0.0.28",
|
31
|
+
"@nestjs/mapped-types": "^2.0.5",
|
32
|
+
"ts-node": "^10.9.1",
|
33
|
+
"typescript": "^5.1.3"
|
34
|
+
},
|
35
|
+
"peerDependencies": {
|
36
|
+
"@hedhog/locale": "latest",
|
37
|
+
"@hedhog/mail": "latest",
|
38
|
+
"@hedhog/pagination": "latest",
|
39
|
+
"@hedhog/prisma": "latest",
|
40
|
+
"@hedhog/utils": "latest",
|
41
|
+
"@nestjs/jwt": "latest"
|
42
|
+
}
|
43
|
+
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Public, Role, User } from '@hedhog/core';
|
1
2
|
import {
|
2
3
|
Body,
|
3
4
|
Controller,
|
@@ -6,12 +7,12 @@ import {
|
|
6
7
|
Inject,
|
7
8
|
Post,
|
8
9
|
} from '@nestjs/common';
|
9
|
-
import { Role, Public, User } from '@hedhog/core';
|
10
10
|
import { AuthService } from './auth.service';
|
11
11
|
import { ForgetDTO } from './dto/forget.dto';
|
12
|
-
import { ResetDTO } from './dto/reset.dto';
|
13
12
|
import { LoginDTO } from './dto/login.dto';
|
14
13
|
import { OtpDTO } from './dto/otp.dto';
|
14
|
+
import { ResetDTO } from './dto/reset.dto';
|
15
|
+
import { SignupDTO } from './dto/signup.dto';
|
15
16
|
import { User as UserType } from './types/user.type';
|
16
17
|
|
17
18
|
@Controller('auth')
|
@@ -19,7 +20,7 @@ export class AuthController {
|
|
19
20
|
constructor(
|
20
21
|
@Inject(forwardRef(() => AuthService))
|
21
22
|
private readonly service: AuthService,
|
22
|
-
) {
|
23
|
+
) {}
|
23
24
|
|
24
25
|
@Role()
|
25
26
|
@Get('verify')
|
@@ -41,14 +42,17 @@ export class AuthController {
|
|
41
42
|
|
42
43
|
@Public()
|
43
44
|
@Post('forget')
|
44
|
-
async forget(
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
async forget(
|
46
|
+
@Body()
|
47
|
+
{
|
48
|
+
email,
|
49
|
+
subject,
|
50
|
+
body,
|
51
|
+
}: ForgetDTO & {
|
52
|
+
subject: string;
|
53
|
+
body: string;
|
54
|
+
},
|
55
|
+
) {
|
52
56
|
return this.service.forget({
|
53
57
|
email,
|
54
58
|
subject,
|
@@ -58,15 +62,17 @@ export class AuthController {
|
|
58
62
|
|
59
63
|
@Public()
|
60
64
|
@Post('reset')
|
61
|
-
async reset(@Body() {
|
62
|
-
newPassword,
|
63
|
-
confirmNewPassword,
|
64
|
-
code,
|
65
|
-
}: ResetDTO) {
|
65
|
+
async reset(@Body() { newPassword, confirmNewPassword, code }: ResetDTO) {
|
66
66
|
return this.service.resetPassword({
|
67
67
|
newPassword,
|
68
68
|
confirmNewPassword,
|
69
69
|
code,
|
70
70
|
});
|
71
71
|
}
|
72
|
+
|
73
|
+
@Public()
|
74
|
+
@Post('signup')
|
75
|
+
async signup(@Body() { fullName, cpf, email, password }: SignupDTO) {
|
76
|
+
return this.service.signup({ fullName, cpf, email, password });
|
77
|
+
}
|
72
78
|
}
|
package/src/auth/auth.service.ts
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
import { MailService } from '@hedhog/mail';
|
2
2
|
import { PrismaService } from '@hedhog/prisma';
|
3
3
|
import {
|
4
|
+
BadRequestException,
|
4
5
|
forwardRef,
|
5
6
|
Inject,
|
6
7
|
Injectable,
|
7
8
|
NotFoundException,
|
8
|
-
BadRequestException,
|
9
9
|
} from '@nestjs/common';
|
10
10
|
import { JwtService } from '@nestjs/jwt';
|
11
11
|
import { compare, genSalt, hash } from 'bcrypt';
|
12
|
+
import { User } from 'hcode-core';
|
13
|
+
import { getBody } from './consts/body';
|
14
|
+
import { SUBJECT_RECOVERY } from './consts/subject';
|
12
15
|
import { ForgetDTO } from './dto/forget.dto';
|
13
16
|
import { LoginDTO } from './dto/login.dto';
|
14
17
|
import { OtpDTO } from './dto/otp.dto';
|
18
|
+
import { SignupDTO } from './dto/signup.dto';
|
15
19
|
import { MultifactorType } from './enums/multifactor-type.enum';
|
16
|
-
import { User } from 'hcode-core';
|
17
|
-
import { SUBJECT_RECOVERY } from './consts/subject';
|
18
|
-
import { getBody } from './consts/body';
|
19
20
|
|
20
21
|
@Injectable()
|
21
22
|
export class AuthService {
|
@@ -26,7 +27,7 @@ export class AuthService {
|
|
26
27
|
private readonly jwt: JwtService,
|
27
28
|
@Inject(forwardRef(() => MailService))
|
28
29
|
private readonly mail: MailService,
|
29
|
-
) {
|
30
|
+
) {}
|
30
31
|
|
31
32
|
async verifyToken(token: string) {
|
32
33
|
return this.jwt.verifyAsync(token, {
|
@@ -52,7 +53,7 @@ export class AuthService {
|
|
52
53
|
}
|
53
54
|
|
54
55
|
async loginWithEmailAndPassword(email: string, password: string) {
|
55
|
-
const user = await
|
56
|
+
const user = await this.prisma.user.findFirst({
|
56
57
|
where: {
|
57
58
|
email,
|
58
59
|
},
|
@@ -73,7 +74,7 @@ export class AuthService {
|
|
73
74
|
if (user.multifactor_id === MultifactorType.EMAIL) {
|
74
75
|
const code = this.generateRandomNumber();
|
75
76
|
|
76
|
-
await
|
77
|
+
await this.prisma.user.update({
|
77
78
|
where: {
|
78
79
|
id: user.id,
|
79
80
|
},
|
@@ -117,7 +118,7 @@ export class AuthService {
|
|
117
118
|
subject?: string;
|
118
119
|
body?: string;
|
119
120
|
}) {
|
120
|
-
const user = await
|
121
|
+
const user = await this.prisma.user.findFirst({
|
121
122
|
where: {
|
122
123
|
email,
|
123
124
|
},
|
@@ -136,7 +137,7 @@ export class AuthService {
|
|
136
137
|
|
137
138
|
const code = this.jwt.sign(payload);
|
138
139
|
|
139
|
-
await
|
140
|
+
await this.prisma.user.update({
|
140
141
|
where: {
|
141
142
|
id: user.id,
|
142
143
|
},
|
@@ -171,7 +172,7 @@ export class AuthService {
|
|
171
172
|
|
172
173
|
const { id } = this.jwt.decode(code) as User;
|
173
174
|
|
174
|
-
const user = await
|
175
|
+
const user = await this.prisma.user.findFirst({
|
175
176
|
where: {
|
176
177
|
id,
|
177
178
|
code,
|
@@ -182,7 +183,7 @@ export class AuthService {
|
|
182
183
|
const salt = await genSalt();
|
183
184
|
const password = await hash(confirmNewPassword, salt);
|
184
185
|
|
185
|
-
await
|
186
|
+
await this.prisma.user.update({
|
186
187
|
where: {
|
187
188
|
id: user.id,
|
188
189
|
},
|
@@ -201,7 +202,7 @@ export class AuthService {
|
|
201
202
|
async otp({ token, code }: OtpDTO) {
|
202
203
|
const data = this.jwt.decode(token);
|
203
204
|
|
204
|
-
const user = await
|
205
|
+
const user = await this.prisma.user.findFirst({
|
205
206
|
where: {
|
206
207
|
id: data['id'],
|
207
208
|
code: String(code),
|
@@ -212,7 +213,7 @@ export class AuthService {
|
|
212
213
|
throw new NotFoundException('Invalid code');
|
213
214
|
}
|
214
215
|
|
215
|
-
await
|
216
|
+
await this.prisma.user.update({
|
216
217
|
where: {
|
217
218
|
id: user.id,
|
218
219
|
},
|
@@ -229,6 +230,31 @@ export class AuthService {
|
|
229
230
|
}
|
230
231
|
|
231
232
|
verify(id: number) {
|
232
|
-
return
|
233
|
+
return this.prisma.user.findUnique({ where: { id } });
|
234
|
+
}
|
235
|
+
|
236
|
+
async signup({ fullName, cpf, email, password }: SignupDTO) {
|
237
|
+
const existingUser = await this.prisma.user.findFirst({
|
238
|
+
where: {
|
239
|
+
OR: [{ email }],
|
240
|
+
},
|
241
|
+
});
|
242
|
+
|
243
|
+
if (existingUser) {
|
244
|
+
throw new BadRequestException('User already exists.');
|
245
|
+
}
|
246
|
+
|
247
|
+
const salt = await genSalt();
|
248
|
+
const hashedPassword = await hash(password, salt);
|
249
|
+
|
250
|
+
const user = await this.prisma.user.create({
|
251
|
+
data: {
|
252
|
+
email,
|
253
|
+
password: hashedPassword,
|
254
|
+
name: fullName,
|
255
|
+
},
|
256
|
+
});
|
257
|
+
|
258
|
+
return this.getToken(user);
|
233
259
|
}
|
234
260
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { IS_PUBLIC_KEY } from '@hedhog/core';
|
1
2
|
import {
|
2
3
|
CanActivate,
|
3
4
|
ExecutionContext,
|
@@ -7,7 +8,6 @@ import {
|
|
7
8
|
import { Reflector } from '@nestjs/core';
|
8
9
|
import { Request } from 'express';
|
9
10
|
import { AuthService } from '../auth.service';
|
10
|
-
import { IS_PUBLIC_KEY } from '@hedhog/core';
|
11
11
|
|
12
12
|
@Injectable()
|
13
13
|
export class AuthGuard implements CanActivate {
|
@@ -22,22 +22,26 @@ export class AuthGuard implements CanActivate {
|
|
22
22
|
context.getClass(),
|
23
23
|
]);
|
24
24
|
|
25
|
-
if (isPublic) {
|
26
|
-
return true;
|
27
|
-
}
|
28
|
-
|
29
25
|
const request = context.switchToHttp().getRequest();
|
30
26
|
const token = this.extractTokenFromHeader(request);
|
31
27
|
|
32
28
|
if (!token) {
|
33
|
-
|
29
|
+
if (isPublic) {
|
30
|
+
return true;
|
31
|
+
} else {
|
32
|
+
throw new UnauthorizedException();
|
33
|
+
}
|
34
34
|
}
|
35
35
|
try {
|
36
36
|
const payload = await this.auth.verifyToken(token);
|
37
37
|
|
38
38
|
request['auth'] = payload;
|
39
39
|
} catch (error) {
|
40
|
-
|
40
|
+
if (isPublic) {
|
41
|
+
return true;
|
42
|
+
} else {
|
43
|
+
throw new UnauthorizedException(error);
|
44
|
+
}
|
41
45
|
}
|
42
46
|
return true;
|
43
47
|
}
|