@j3r3mcdev/auth-service 1.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/dist/auth/auth.controller.d.ts +60 -0
- package/dist/auth/auth.controller.d.ts.map +1 -0
- package/dist/auth/auth.controller.js +128 -0
- package/dist/auth/auth.module.d.ts +3 -0
- package/dist/auth/auth.module.d.ts.map +1 -0
- package/dist/auth/auth.module.js +44 -0
- package/dist/auth/auth.repository.d.ts +119 -0
- package/dist/auth/auth.repository.d.ts.map +1 -0
- package/dist/auth/auth.repository.js +108 -0
- package/dist/auth/auth.service.d.ts +61 -0
- package/dist/auth/auth.service.d.ts.map +1 -0
- package/dist/auth/auth.service.js +287 -0
- package/dist/auth/dto/forgot-password.dto.d.ts +4 -0
- package/dist/auth/dto/forgot-password.dto.d.ts.map +1 -0
- package/dist/auth/dto/forgot-password.dto.js +21 -0
- package/dist/auth/dto/login.dto.d.ts +5 -0
- package/dist/auth/dto/login.dto.d.ts.map +1 -0
- package/dist/auth/dto/login.dto.js +26 -0
- package/dist/auth/dto/refresh.dto.d.ts +4 -0
- package/dist/auth/dto/refresh.dto.d.ts.map +1 -0
- package/dist/auth/dto/refresh.dto.js +21 -0
- package/dist/auth/dto/register.dto.d.ts +5 -0
- package/dist/auth/dto/register.dto.d.ts.map +1 -0
- package/dist/auth/dto/register.dto.js +27 -0
- package/dist/auth/dto/reset-password.dto.d.ts +5 -0
- package/dist/auth/dto/reset-password.dto.d.ts.map +1 -0
- package/dist/auth/dto/reset-password.dto.js +27 -0
- package/dist/auth/dto/update-user.dto.d.ts +5 -0
- package/dist/auth/dto/update-user.dto.d.ts.map +1 -0
- package/dist/auth/dto/update-user.dto.js +28 -0
- package/dist/auth/guards/jwt.guard.d.ts +5 -0
- package/dist/auth/guards/jwt.guard.d.ts.map +1 -0
- package/dist/auth/guards/jwt.guard.js +18 -0
- package/dist/auth/guards/jwt.refresh-guard.d.ts +5 -0
- package/dist/auth/guards/jwt.refresh-guard.d.ts.map +1 -0
- package/dist/auth/guards/jwt.refresh-guard.js +18 -0
- package/dist/auth/strategies/jwt-refresh.strategy.d.ts +22 -0
- package/dist/auth/strategies/jwt-refresh.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/jwt-refresh.strategy.js +45 -0
- package/dist/auth/strategies/jwt.strategy.d.ts +10 -0
- package/dist/auth/strategies/jwt.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/jwt.strategy.js +33 -0
- package/dist/auth/strategies/strategies/jwt-refresh.strategy.d.ts +22 -0
- package/dist/auth/strategies/strategies/jwt-refresh.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/strategies/jwt-refresh.strategy.js +45 -0
- package/dist/auth/strategies/strategies/jwt.strategy.d.ts +10 -0
- package/dist/auth/strategies/strategies/jwt.strategy.d.ts.map +1 -0
- package/dist/auth/strategies/strategies/jwt.strategy.js +33 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/package.json +18 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Request } from 'express';
|
|
2
|
+
import { AuthService } from './auth.service';
|
|
3
|
+
import { RegisterDto } from './dto/register.dto';
|
|
4
|
+
import { LoginDto } from './dto/login.dto';
|
|
5
|
+
import { RefreshDto } from './dto/refresh.dto';
|
|
6
|
+
import { UpdateUserDto } from './dto/update-user.dto';
|
|
7
|
+
import { ForgotPasswordDto } from './dto/forgot-password.dto';
|
|
8
|
+
import { ResetPasswordDto } from './dto/reset-password.dto';
|
|
9
|
+
type AuthRequest = Request & {
|
|
10
|
+
user: {
|
|
11
|
+
sub: string;
|
|
12
|
+
email: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare class AuthController {
|
|
16
|
+
private readonly authService;
|
|
17
|
+
constructor(authService: AuthService);
|
|
18
|
+
register(dto: RegisterDto): Promise<{
|
|
19
|
+
accessToken: string;
|
|
20
|
+
refreshToken: string;
|
|
21
|
+
message: string;
|
|
22
|
+
}>;
|
|
23
|
+
login(dto: LoginDto): Promise<{
|
|
24
|
+
accessToken: string;
|
|
25
|
+
refreshToken: string;
|
|
26
|
+
message: string;
|
|
27
|
+
}>;
|
|
28
|
+
me(req: AuthRequest): Promise<{
|
|
29
|
+
sub: string;
|
|
30
|
+
email: string;
|
|
31
|
+
}>;
|
|
32
|
+
updateUser(req: AuthRequest, dto: UpdateUserDto): Promise<{
|
|
33
|
+
message: string;
|
|
34
|
+
user: {
|
|
35
|
+
id: string;
|
|
36
|
+
email: string;
|
|
37
|
+
};
|
|
38
|
+
email?: undefined;
|
|
39
|
+
} | {
|
|
40
|
+
message: string;
|
|
41
|
+
email: string;
|
|
42
|
+
user?: undefined;
|
|
43
|
+
}>;
|
|
44
|
+
logout(req: AuthRequest): Promise<{
|
|
45
|
+
message: string;
|
|
46
|
+
}>;
|
|
47
|
+
refresh(req: any, dto: RefreshDto): Promise<{
|
|
48
|
+
accessToken: string;
|
|
49
|
+
refreshToken: string;
|
|
50
|
+
message: string;
|
|
51
|
+
}>;
|
|
52
|
+
forgotPassword(dto: ForgotPasswordDto): Promise<string | {
|
|
53
|
+
message: string;
|
|
54
|
+
} | undefined>;
|
|
55
|
+
resetPassword(dto: ResetPasswordDto): Promise<{
|
|
56
|
+
message: string;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=auth.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,KAAK,WAAW,GAAG,OAAO,GAAG;IAC3B,IAAI,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF,qBACa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAG/C,QAAQ,CAAS,GAAG,EAAE,WAAW;;;;;IAMjC,KAAK,CAAS,GAAG,EAAE,QAAQ;;;;;IAM3B,EAAE,CAAQ,GAAG,EAAE,WAAW;;;;IAO1B,UAAU,CAAQ,GAAG,EAAE,WAAW,EAAU,GAAG,EAAE,aAAa;;;;;;;;;;;;IAO9D,MAAM,CAAQ,GAAG,EAAE,WAAW;;;IAM9B,OAAO,CAAQ,GAAG,EAAE,GAAG,EAAU,GAAG,EAAE,UAAU;;;;;IAKhD,cAAc,CAAS,GAAG,EAAE,iBAAiB;;;IAW7C,aAAa,CAAS,GAAG,EAAE,gBAAgB;;;CAGlD"}
|
|
@@ -0,0 +1,128 @@
|
|
|
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 auth_service_1 = require("./auth.service");
|
|
18
|
+
const register_dto_1 = require("./dto/register.dto");
|
|
19
|
+
const login_dto_1 = require("./dto/login.dto");
|
|
20
|
+
const refresh_dto_1 = require("./dto/refresh.dto");
|
|
21
|
+
const update_user_dto_1 = require("./dto/update-user.dto");
|
|
22
|
+
const forgot_password_dto_1 = require("./dto/forgot-password.dto");
|
|
23
|
+
const reset_password_dto_1 = require("./dto/reset-password.dto");
|
|
24
|
+
const jwt_guard_1 = require("./guards/jwt.guard");
|
|
25
|
+
let AuthController = class AuthController {
|
|
26
|
+
authService;
|
|
27
|
+
constructor(authService) {
|
|
28
|
+
this.authService = authService;
|
|
29
|
+
}
|
|
30
|
+
async register(dto) {
|
|
31
|
+
return this.authService.register(dto);
|
|
32
|
+
}
|
|
33
|
+
async login(dto) {
|
|
34
|
+
return this.authService.login(dto);
|
|
35
|
+
}
|
|
36
|
+
async me(req) {
|
|
37
|
+
return this.authService.me(req.user.sub);
|
|
38
|
+
}
|
|
39
|
+
async updateUser(req, dto) {
|
|
40
|
+
return this.authService.updateUser(req.user.sub, dto);
|
|
41
|
+
}
|
|
42
|
+
async logout(req) {
|
|
43
|
+
return this.authService.logout(req.user.sub);
|
|
44
|
+
}
|
|
45
|
+
async refresh(req, dto) {
|
|
46
|
+
return this.authService.refresh(dto);
|
|
47
|
+
}
|
|
48
|
+
async forgotPassword(dto) {
|
|
49
|
+
const token = await this.authService.forgotPassword(dto);
|
|
50
|
+
if (process.env.NODE_ENV === 'test:e2e') {
|
|
51
|
+
return token; // ✔ renvoie la string brute
|
|
52
|
+
}
|
|
53
|
+
return { message: 'Reset email sent' };
|
|
54
|
+
}
|
|
55
|
+
async resetPassword(dto) {
|
|
56
|
+
return this.authService.resetPassword(dto);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.AuthController = AuthController;
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, common_1.Post)('register'),
|
|
62
|
+
__param(0, (0, common_1.Body)()),
|
|
63
|
+
__metadata("design:type", Function),
|
|
64
|
+
__metadata("design:paramtypes", [register_dto_1.RegisterDto]),
|
|
65
|
+
__metadata("design:returntype", Promise)
|
|
66
|
+
], AuthController.prototype, "register", null);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
69
|
+
(0, common_1.Post)('login'),
|
|
70
|
+
__param(0, (0, common_1.Body)()),
|
|
71
|
+
__metadata("design:type", Function),
|
|
72
|
+
__metadata("design:paramtypes", [login_dto_1.LoginDto]),
|
|
73
|
+
__metadata("design:returntype", Promise)
|
|
74
|
+
], AuthController.prototype, "login", null);
|
|
75
|
+
__decorate([
|
|
76
|
+
(0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
|
|
77
|
+
(0, common_1.Get)('me'),
|
|
78
|
+
__param(0, (0, common_1.Req)()),
|
|
79
|
+
__metadata("design:type", Function),
|
|
80
|
+
__metadata("design:paramtypes", [Object]),
|
|
81
|
+
__metadata("design:returntype", Promise)
|
|
82
|
+
], AuthController.prototype, "me", null);
|
|
83
|
+
__decorate([
|
|
84
|
+
(0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
|
|
85
|
+
(0, common_1.Patch)('update'),
|
|
86
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
87
|
+
__param(0, (0, common_1.Req)()),
|
|
88
|
+
__param(1, (0, common_1.Body)()),
|
|
89
|
+
__metadata("design:type", Function),
|
|
90
|
+
__metadata("design:paramtypes", [Object, update_user_dto_1.UpdateUserDto]),
|
|
91
|
+
__metadata("design:returntype", Promise)
|
|
92
|
+
], AuthController.prototype, "updateUser", null);
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
|
|
95
|
+
(0, common_1.Post)('logout'),
|
|
96
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
97
|
+
__param(0, (0, common_1.Req)()),
|
|
98
|
+
__metadata("design:type", Function),
|
|
99
|
+
__metadata("design:paramtypes", [Object]),
|
|
100
|
+
__metadata("design:returntype", Promise)
|
|
101
|
+
], AuthController.prototype, "logout", null);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, common_1.Post)('refresh'),
|
|
104
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
105
|
+
__param(0, (0, common_1.Req)()),
|
|
106
|
+
__param(1, (0, common_1.Body)()),
|
|
107
|
+
__metadata("design:type", Function),
|
|
108
|
+
__metadata("design:paramtypes", [Object, refresh_dto_1.RefreshDto]),
|
|
109
|
+
__metadata("design:returntype", Promise)
|
|
110
|
+
], AuthController.prototype, "refresh", null);
|
|
111
|
+
__decorate([
|
|
112
|
+
(0, common_1.Post)('forgot-password'),
|
|
113
|
+
__param(0, (0, common_1.Body)()),
|
|
114
|
+
__metadata("design:type", Function),
|
|
115
|
+
__metadata("design:paramtypes", [forgot_password_dto_1.ForgotPasswordDto]),
|
|
116
|
+
__metadata("design:returntype", Promise)
|
|
117
|
+
], AuthController.prototype, "forgotPassword", null);
|
|
118
|
+
__decorate([
|
|
119
|
+
(0, common_1.Post)('reset-password'),
|
|
120
|
+
__param(0, (0, common_1.Body)()),
|
|
121
|
+
__metadata("design:type", Function),
|
|
122
|
+
__metadata("design:paramtypes", [reset_password_dto_1.ResetPasswordDto]),
|
|
123
|
+
__metadata("design:returntype", Promise)
|
|
124
|
+
], AuthController.prototype, "resetPassword", null);
|
|
125
|
+
exports.AuthController = AuthController = __decorate([
|
|
126
|
+
(0, common_1.Controller)('auth'),
|
|
127
|
+
__metadata("design:paramtypes", [auth_service_1.AuthService])
|
|
128
|
+
], AuthController);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.module.d.ts","sourceRoot":"","sources":["../../src/auth/auth.module.ts"],"names":[],"mappings":"AAaA,qBAuBa,UAAU;CAAG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// cSpell: disable
|
|
3
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
4
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
6
|
+
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;
|
|
7
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AuthModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
13
|
+
const client_1 = require("@prisma/client");
|
|
14
|
+
const auth_controller_1 = require("./auth.controller");
|
|
15
|
+
const auth_service_1 = require("./auth.service");
|
|
16
|
+
const auth_repository_1 = require("./auth.repository");
|
|
17
|
+
const jwt_strategy_1 = require("./strategies/jwt.strategy");
|
|
18
|
+
const jwt_refresh_strategy_1 = require("./strategies/jwt-refresh.strategy");
|
|
19
|
+
let AuthModule = class AuthModule {
|
|
20
|
+
};
|
|
21
|
+
exports.AuthModule = AuthModule;
|
|
22
|
+
exports.AuthModule = AuthModule = __decorate([
|
|
23
|
+
(0, common_1.Module)({
|
|
24
|
+
imports: [
|
|
25
|
+
jwt_1.JwtModule.register({
|
|
26
|
+
secret: process.env.JWT_SECRET,
|
|
27
|
+
signOptions: { expiresIn: '15m' },
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
controllers: [auth_controller_1.AuthController],
|
|
31
|
+
providers: [
|
|
32
|
+
auth_service_1.AuthService,
|
|
33
|
+
auth_repository_1.AuthRepository,
|
|
34
|
+
// PrismaClient pour une librairie NPM
|
|
35
|
+
{
|
|
36
|
+
provide: client_1.PrismaClient,
|
|
37
|
+
useValue: new client_1.PrismaClient(),
|
|
38
|
+
},
|
|
39
|
+
jwt_strategy_1.JwtStrategy,
|
|
40
|
+
jwt_refresh_strategy_1.JwtRefreshStrategy,
|
|
41
|
+
],
|
|
42
|
+
exports: [auth_service_1.AuthService],
|
|
43
|
+
})
|
|
44
|
+
], AuthModule);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { PrismaClient } from '@prisma/client';
|
|
2
|
+
export declare class AuthRepository {
|
|
3
|
+
private prisma;
|
|
4
|
+
constructor(prisma: PrismaClient);
|
|
5
|
+
createUser(data: {
|
|
6
|
+
email: string;
|
|
7
|
+
password: string;
|
|
8
|
+
}): import(".prisma/client").Prisma.Prisma__UserClient<{
|
|
9
|
+
id: string;
|
|
10
|
+
email: string;
|
|
11
|
+
password: string;
|
|
12
|
+
refreshToken: string | null;
|
|
13
|
+
resetToken: string | null;
|
|
14
|
+
resetTokenExpiresAt: Date | null;
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
updatedAt: Date;
|
|
17
|
+
}, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
18
|
+
findByEmail(email: string): import(".prisma/client").Prisma.Prisma__UserClient<{
|
|
19
|
+
id: string;
|
|
20
|
+
email: string;
|
|
21
|
+
password: string;
|
|
22
|
+
refreshToken: string | null;
|
|
23
|
+
resetToken: string | null;
|
|
24
|
+
resetTokenExpiresAt: Date | null;
|
|
25
|
+
createdAt: Date;
|
|
26
|
+
updatedAt: Date;
|
|
27
|
+
} | null, null, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
28
|
+
findById(id: string): import(".prisma/client").Prisma.Prisma__UserClient<{
|
|
29
|
+
id: string;
|
|
30
|
+
email: string;
|
|
31
|
+
password: string;
|
|
32
|
+
refreshToken: string | null;
|
|
33
|
+
resetToken: string | null;
|
|
34
|
+
resetTokenExpiresAt: Date | null;
|
|
35
|
+
createdAt: Date;
|
|
36
|
+
updatedAt: Date;
|
|
37
|
+
} | null, null, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
38
|
+
updateUser(id: string, data: any): import(".prisma/client").Prisma.Prisma__UserClient<{
|
|
39
|
+
id: string;
|
|
40
|
+
email: string;
|
|
41
|
+
password: string;
|
|
42
|
+
refreshToken: string | null;
|
|
43
|
+
resetToken: string | null;
|
|
44
|
+
resetTokenExpiresAt: Date | null;
|
|
45
|
+
createdAt: Date;
|
|
46
|
+
updatedAt: Date;
|
|
47
|
+
}, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
48
|
+
updateRefreshToken(id: string, refreshToken: string | null): import(".prisma/client").Prisma.Prisma__UserClient<{
|
|
49
|
+
id: string;
|
|
50
|
+
email: string;
|
|
51
|
+
password: string;
|
|
52
|
+
refreshToken: string | null;
|
|
53
|
+
resetToken: string | null;
|
|
54
|
+
resetTokenExpiresAt: Date | null;
|
|
55
|
+
createdAt: Date;
|
|
56
|
+
updatedAt: Date;
|
|
57
|
+
}, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
58
|
+
clearRefreshToken(id: string): import(".prisma/client").Prisma.Prisma__UserClient<{
|
|
59
|
+
id: string;
|
|
60
|
+
email: string;
|
|
61
|
+
password: string;
|
|
62
|
+
refreshToken: string | null;
|
|
63
|
+
resetToken: string | null;
|
|
64
|
+
resetTokenExpiresAt: Date | null;
|
|
65
|
+
createdAt: Date;
|
|
66
|
+
updatedAt: Date;
|
|
67
|
+
}, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
68
|
+
setResetToken(id: string, tokenHash: string, expiresAt: Date): import(".prisma/client").Prisma.Prisma__UserClient<{
|
|
69
|
+
id: string;
|
|
70
|
+
email: string;
|
|
71
|
+
password: string;
|
|
72
|
+
refreshToken: string | null;
|
|
73
|
+
resetToken: string | null;
|
|
74
|
+
resetTokenExpiresAt: Date | null;
|
|
75
|
+
createdAt: Date;
|
|
76
|
+
updatedAt: Date;
|
|
77
|
+
}, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
78
|
+
/**
|
|
79
|
+
* IMPORTANT :
|
|
80
|
+
* On NE filtre PLUS l'expiration ici.
|
|
81
|
+
* Le service reset-password gère déjà :
|
|
82
|
+
* - token invalide
|
|
83
|
+
* - token expiré
|
|
84
|
+
* - token absent
|
|
85
|
+
*
|
|
86
|
+
* Donc ici on doit juste retrouver l'utilisateur par resetToken.
|
|
87
|
+
*/
|
|
88
|
+
findByResetToken(tokenHash: string): import(".prisma/client").Prisma.Prisma__UserClient<{
|
|
89
|
+
id: string;
|
|
90
|
+
email: string;
|
|
91
|
+
password: string;
|
|
92
|
+
refreshToken: string | null;
|
|
93
|
+
resetToken: string | null;
|
|
94
|
+
resetTokenExpiresAt: Date | null;
|
|
95
|
+
createdAt: Date;
|
|
96
|
+
updatedAt: Date;
|
|
97
|
+
} | null, null, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
98
|
+
clearResetToken(id: string): import(".prisma/client").Prisma.Prisma__UserClient<{
|
|
99
|
+
id: string;
|
|
100
|
+
email: string;
|
|
101
|
+
password: string;
|
|
102
|
+
refreshToken: string | null;
|
|
103
|
+
resetToken: string | null;
|
|
104
|
+
resetTokenExpiresAt: Date | null;
|
|
105
|
+
createdAt: Date;
|
|
106
|
+
updatedAt: Date;
|
|
107
|
+
}, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
108
|
+
updatePassword(id: string, hashedPassword: string): import(".prisma/client").Prisma.Prisma__UserClient<{
|
|
109
|
+
id: string;
|
|
110
|
+
email: string;
|
|
111
|
+
password: string;
|
|
112
|
+
refreshToken: string | null;
|
|
113
|
+
resetToken: string | null;
|
|
114
|
+
resetTokenExpiresAt: Date | null;
|
|
115
|
+
createdAt: Date;
|
|
116
|
+
updatedAt: Date;
|
|
117
|
+
}, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=auth.repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.repository.d.ts","sourceRoot":"","sources":["../../src/auth/auth.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBACa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAMxC,UAAU,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;IAIpD,WAAW,CAAC,KAAK,EAAE,MAAM;;;;;;;;;;IAMzB,QAAQ,CAAC,EAAE,EAAE,MAAM;;;;;;;;;;IAMnB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;;;;;;;;;;IAWhC,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;;;;;;;;;;IAO1D,iBAAiB,CAAC,EAAE,EAAE,MAAM;;;;;;;;;;IAW5B,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI;;;;;;;;;;IAU5D;;;;;;;;;OASG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM;;;;;;;;;;IAQlC,eAAe,CAAC,EAAE,EAAE,MAAM;;;;;;;;;;IAU1B,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;;;;;;;;;;CAQlD"}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthRepository = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const client_1 = require("@prisma/client");
|
|
15
|
+
let AuthRepository = class AuthRepository {
|
|
16
|
+
prisma;
|
|
17
|
+
constructor(prisma) {
|
|
18
|
+
this.prisma = prisma;
|
|
19
|
+
}
|
|
20
|
+
// -------------------------
|
|
21
|
+
// USERS
|
|
22
|
+
// -------------------------
|
|
23
|
+
createUser(data) {
|
|
24
|
+
return this.prisma.user.create({ data });
|
|
25
|
+
}
|
|
26
|
+
findByEmail(email) {
|
|
27
|
+
return this.prisma.user.findUnique({
|
|
28
|
+
where: { email },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
findById(id) {
|
|
32
|
+
return this.prisma.user.findUnique({
|
|
33
|
+
where: { id },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
updateUser(id, data) {
|
|
37
|
+
return this.prisma.user.update({
|
|
38
|
+
where: { id },
|
|
39
|
+
data,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
// -------------------------
|
|
43
|
+
// REFRESH TOKEN
|
|
44
|
+
// -------------------------
|
|
45
|
+
updateRefreshToken(id, refreshToken) {
|
|
46
|
+
return this.prisma.user.update({
|
|
47
|
+
where: { id },
|
|
48
|
+
data: { refreshToken },
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
clearRefreshToken(id) {
|
|
52
|
+
return this.prisma.user.update({
|
|
53
|
+
where: { id },
|
|
54
|
+
data: { refreshToken: null },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// -------------------------
|
|
58
|
+
// RESET PASSWORD
|
|
59
|
+
// -------------------------
|
|
60
|
+
setResetToken(id, tokenHash, expiresAt) {
|
|
61
|
+
return this.prisma.user.update({
|
|
62
|
+
where: { id },
|
|
63
|
+
data: {
|
|
64
|
+
resetToken: tokenHash,
|
|
65
|
+
resetTokenExpiresAt: expiresAt,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* IMPORTANT :
|
|
71
|
+
* On NE filtre PLUS l'expiration ici.
|
|
72
|
+
* Le service reset-password gère déjà :
|
|
73
|
+
* - token invalide
|
|
74
|
+
* - token expiré
|
|
75
|
+
* - token absent
|
|
76
|
+
*
|
|
77
|
+
* Donc ici on doit juste retrouver l'utilisateur par resetToken.
|
|
78
|
+
*/
|
|
79
|
+
findByResetToken(tokenHash) {
|
|
80
|
+
return this.prisma.user.findFirst({
|
|
81
|
+
where: {
|
|
82
|
+
resetToken: tokenHash, // ✔ plus de resetTokenExpiresAt: { gt: new Date() }
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
clearResetToken(id) {
|
|
87
|
+
return this.prisma.user.update({
|
|
88
|
+
where: { id },
|
|
89
|
+
data: {
|
|
90
|
+
resetToken: null,
|
|
91
|
+
resetTokenExpiresAt: null,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
updatePassword(id, hashedPassword) {
|
|
96
|
+
return this.prisma.user.update({
|
|
97
|
+
where: { id },
|
|
98
|
+
data: {
|
|
99
|
+
password: hashedPassword,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
exports.AuthRepository = AuthRepository;
|
|
105
|
+
exports.AuthRepository = AuthRepository = __decorate([
|
|
106
|
+
(0, common_1.Injectable)(),
|
|
107
|
+
__metadata("design:paramtypes", [client_1.PrismaClient])
|
|
108
|
+
], AuthRepository);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AuthRepository } from './auth.repository';
|
|
2
|
+
import { JwtService } from '@nestjs/jwt';
|
|
3
|
+
import { RegisterDto } from './dto/register.dto';
|
|
4
|
+
import { LoginDto } from './dto/login.dto';
|
|
5
|
+
import { RefreshDto } from './dto/refresh.dto';
|
|
6
|
+
import { UpdateUserDto } from './dto/update-user.dto';
|
|
7
|
+
import { ForgotPasswordDto } from './dto/forgot-password.dto';
|
|
8
|
+
import { ResetPasswordDto } from './dto/reset-password.dto';
|
|
9
|
+
export declare class AuthService {
|
|
10
|
+
private readonly repo;
|
|
11
|
+
private readonly jwt;
|
|
12
|
+
private readonly isE2E;
|
|
13
|
+
constructor(repo: AuthRepository, jwt: JwtService);
|
|
14
|
+
sha256(data: string): string;
|
|
15
|
+
generateTokens(user: {
|
|
16
|
+
id: string;
|
|
17
|
+
email: string;
|
|
18
|
+
}): {
|
|
19
|
+
accessToken: string;
|
|
20
|
+
refreshToken: string;
|
|
21
|
+
};
|
|
22
|
+
register(dto: RegisterDto): Promise<{
|
|
23
|
+
accessToken: string;
|
|
24
|
+
refreshToken: string;
|
|
25
|
+
message: string;
|
|
26
|
+
}>;
|
|
27
|
+
login(dto: LoginDto): Promise<{
|
|
28
|
+
accessToken: string;
|
|
29
|
+
refreshToken: string;
|
|
30
|
+
message: string;
|
|
31
|
+
}>;
|
|
32
|
+
me(userId: string): Promise<{
|
|
33
|
+
sub: string;
|
|
34
|
+
email: string;
|
|
35
|
+
}>;
|
|
36
|
+
updateUser(userId: string, dto: UpdateUserDto): Promise<{
|
|
37
|
+
message: string;
|
|
38
|
+
user: {
|
|
39
|
+
id: string;
|
|
40
|
+
email: string;
|
|
41
|
+
};
|
|
42
|
+
email?: undefined;
|
|
43
|
+
} | {
|
|
44
|
+
message: string;
|
|
45
|
+
email: string;
|
|
46
|
+
user?: undefined;
|
|
47
|
+
}>;
|
|
48
|
+
logout(userId: string): Promise<{
|
|
49
|
+
message: string;
|
|
50
|
+
}>;
|
|
51
|
+
refresh(dto: RefreshDto): Promise<{
|
|
52
|
+
accessToken: string;
|
|
53
|
+
refreshToken: string;
|
|
54
|
+
message: string;
|
|
55
|
+
}>;
|
|
56
|
+
forgotPassword(dto: ForgotPasswordDto): Promise<string | undefined>;
|
|
57
|
+
resetPassword(dto: ResetPasswordDto): Promise<{
|
|
58
|
+
message: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=auth.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,qBACa,WAAW;IAIpB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAJtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuC;gBAG1C,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,UAAU;IAOlC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI5B,cAAc,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;;;;IA+B5C,QAAQ,CAAC,GAAG,EAAE,WAAW;;;;;IAwCzB,KAAK,CAAC,GAAG,EAAE,QAAQ;;;;;IA+BnB,EAAE,CAAC,MAAM,EAAE,MAAM;;;;IAcjB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa;;;;;;;;;;;;IA4B7C,MAAM,CAAC,MAAM,EAAE,MAAM;;;IAkBrB,OAAO,CAAC,GAAG,EAAE,UAAU;;;;;IA8CvB,cAAc,CAAC,GAAG,EAAE,iBAAiB;IAqBrC,aAAa,CAAC,GAAG,EAAE,gBAAgB;;;CAqB1C"}
|