@next-nest-auth/nestauth 1.2.6 → 1.2.8

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.
Files changed (47) hide show
  1. package/dist/src/http-exception.filter.d.ts +4 -0
  2. package/dist/src/http-exception.filter.js +65 -0
  3. package/dist/src/http-exception.filter.js.map +1 -0
  4. package/dist/src/index.d.ts +5 -0
  5. package/dist/src/index.js +22 -0
  6. package/dist/src/index.js.map +1 -0
  7. package/dist/src/nestauth-facebook.guard.d.ts +7 -0
  8. package/dist/src/nestauth-facebook.guard.js +29 -0
  9. package/dist/src/nestauth-facebook.guard.js.map +1 -0
  10. package/dist/src/nestauth-facebook.strategy.d.ts +9 -0
  11. package/dist/src/nestauth-facebook.strategy.js +45 -0
  12. package/dist/src/nestauth-facebook.strategy.js.map +1 -0
  13. package/dist/src/nestauth-google.guard.d.ts +7 -0
  14. package/dist/src/nestauth-google.guard.js +29 -0
  15. package/dist/src/nestauth-google.guard.js.map +1 -0
  16. package/dist/src/nestauth-google.strategy.d.ts +9 -0
  17. package/dist/src/nestauth-google.strategy.js +44 -0
  18. package/dist/src/nestauth-google.strategy.js.map +1 -0
  19. package/dist/src/nestauth-jwt.guard.d.ts +7 -0
  20. package/dist/src/nestauth-jwt.guard.js +40 -0
  21. package/dist/src/nestauth-jwt.guard.js.map +1 -0
  22. package/dist/src/nestauth-jwt.strategy.d.ts +10 -0
  23. package/dist/src/nestauth-jwt.strategy.js +51 -0
  24. package/dist/src/nestauth-jwt.strategy.js.map +1 -0
  25. package/dist/src/nestauth-local.guard.d.ts +20 -0
  26. package/dist/src/nestauth-local.guard.js +20 -0
  27. package/dist/src/nestauth-local.guard.js.map +1 -0
  28. package/dist/src/nestauth-local.strategy.d.ts +14 -0
  29. package/dist/src/nestauth-local.strategy.js +42 -0
  30. package/dist/src/nestauth-local.strategy.js.map +1 -0
  31. package/dist/src/nestauth.controller.d.ts +16 -0
  32. package/dist/src/nestauth.controller.js +126 -0
  33. package/dist/src/nestauth.controller.js.map +1 -0
  34. package/dist/src/nestauth.interface.d.ts +36 -0
  35. package/dist/src/nestauth.interface.js +3 -0
  36. package/dist/src/nestauth.interface.js.map +1 -0
  37. package/dist/src/nestauth.module.d.ts +5 -0
  38. package/dist/src/nestauth.module.js +96 -0
  39. package/dist/src/nestauth.module.js.map +1 -0
  40. package/dist/src/nestauth.service.d.ts +14 -0
  41. package/dist/src/nestauth.service.js +72 -0
  42. package/dist/src/nestauth.service.js.map +1 -0
  43. package/dist/tsconfig.tsbuildinfo +1 -0
  44. package/package.json +61 -61
  45. package/src/nestauth-jwt.guard.ts +25 -27
  46. package/src/nestauth.controller.ts +69 -73
  47. package/src/nestauth.module.ts +91 -96
@@ -0,0 +1,126 @@
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.createDynamicController = createDynamicController;
16
+ const common_1 = require("@nestjs/common");
17
+ const nestauth_service_1 = require("./nestauth.service");
18
+ const nestauth_google_guard_1 = require("./nestauth-google.guard");
19
+ const nestauth_facebook_guard_1 = require("./nestauth-facebook.guard");
20
+ const http_exception_filter_1 = require("./http-exception.filter");
21
+ function createDynamicController(prefix, nestAuthServiceToken, localGuard) {
22
+ let NestAuthController = class NestAuthController {
23
+ constructor(nestAuthService) {
24
+ this.nestAuthService = nestAuthService;
25
+ }
26
+ async greetings() {
27
+ return "Welcome to NestAuth. Please check our documentation for more information.";
28
+ }
29
+ async login(req) {
30
+ return this.nestAuthService.login(req.user);
31
+ }
32
+ refreshToken(params) {
33
+ if (!params.refresh_token) {
34
+ throw new common_1.BadRequestException("Invalid or expired refresh token");
35
+ }
36
+ return this.nestAuthService.refreshToken(params.refresh_token);
37
+ }
38
+ async googleAuth(req) { }
39
+ googleAuthRedirect(req) {
40
+ if (!req.user) {
41
+ throw new common_1.UnauthorizedException("Unable to login with Google");
42
+ }
43
+ return this.nestAuthService.google(req.user);
44
+ }
45
+ async facebookLogin() {
46
+ return common_1.HttpStatus.OK;
47
+ }
48
+ async facebookLoginRedirect(req) {
49
+ if (!req.user) {
50
+ throw new common_1.UnauthorizedException("Unable to login with Facebook");
51
+ }
52
+ return this.nestAuthService.facebook(req.user);
53
+ }
54
+ async logout(req) {
55
+ return req.logout();
56
+ }
57
+ };
58
+ __decorate([
59
+ (0, common_1.All)(),
60
+ __metadata("design:type", Function),
61
+ __metadata("design:paramtypes", []),
62
+ __metadata("design:returntype", Promise)
63
+ ], NestAuthController.prototype, "greetings", null);
64
+ __decorate([
65
+ (0, common_1.UseGuards)(localGuard),
66
+ (0, common_1.Post)("login"),
67
+ __param(0, (0, common_1.Request)()),
68
+ __metadata("design:type", Function),
69
+ __metadata("design:paramtypes", [Object]),
70
+ __metadata("design:returntype", Promise)
71
+ ], NestAuthController.prototype, "login", null);
72
+ __decorate([
73
+ (0, common_1.Post)("refresh-token"),
74
+ __param(0, (0, common_1.Body)()),
75
+ __metadata("design:type", Function),
76
+ __metadata("design:paramtypes", [Object]),
77
+ __metadata("design:returntype", Promise)
78
+ ], NestAuthController.prototype, "refreshToken", null);
79
+ __decorate([
80
+ (0, common_1.UseGuards)(nestauth_google_guard_1.NestAuthGoogleGuard),
81
+ (0, common_1.Get)("google"),
82
+ __param(0, (0, common_1.Request)()),
83
+ __metadata("design:type", Function),
84
+ __metadata("design:paramtypes", [Object]),
85
+ __metadata("design:returntype", Promise)
86
+ ], NestAuthController.prototype, "googleAuth", null);
87
+ __decorate([
88
+ (0, common_1.Get)("google-redirect"),
89
+ (0, common_1.UseGuards)(nestauth_google_guard_1.NestAuthGoogleGuard),
90
+ __param(0, (0, common_1.Request)()),
91
+ __metadata("design:type", Function),
92
+ __metadata("design:paramtypes", [Object]),
93
+ __metadata("design:returntype", void 0)
94
+ ], NestAuthController.prototype, "googleAuthRedirect", null);
95
+ __decorate([
96
+ (0, common_1.Get)("/facebook"),
97
+ (0, common_1.UseGuards)(nestauth_facebook_guard_1.NestAuthFacebookGuard),
98
+ __metadata("design:type", Function),
99
+ __metadata("design:paramtypes", []),
100
+ __metadata("design:returntype", Promise)
101
+ ], NestAuthController.prototype, "facebookLogin", null);
102
+ __decorate([
103
+ (0, common_1.Get)("/facebook-redirect"),
104
+ (0, common_1.UseGuards)(nestauth_facebook_guard_1.NestAuthFacebookGuard),
105
+ __param(0, (0, common_1.Request)()),
106
+ __metadata("design:type", Function),
107
+ __metadata("design:paramtypes", [Object]),
108
+ __metadata("design:returntype", Promise)
109
+ ], NestAuthController.prototype, "facebookLoginRedirect", null);
110
+ __decorate([
111
+ (0, common_1.UseGuards)(localGuard),
112
+ (0, common_1.Get)("logout"),
113
+ __param(0, (0, common_1.Request)()),
114
+ __metadata("design:type", Function),
115
+ __metadata("design:paramtypes", [Object]),
116
+ __metadata("design:returntype", Promise)
117
+ ], NestAuthController.prototype, "logout", null);
118
+ NestAuthController = __decorate([
119
+ (0, common_1.UseFilters)(http_exception_filter_1.HttpExceptionFilter),
120
+ (0, common_1.Controller)(prefix),
121
+ __param(0, (0, common_1.Inject)(nestAuthServiceToken)),
122
+ __metadata("design:paramtypes", [nestauth_service_1.NestAuthService])
123
+ ], NestAuthController);
124
+ return NestAuthController;
125
+ }
126
+ //# sourceMappingURL=nestauth.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nestauth.controller.js","sourceRoot":"","sources":["../../src/nestauth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAmBA,0DAqEC;AAxFD,2CAawB;AACxB,yDAAqD;AACrD,mEAA8D;AAC9D,uEAAkE;AAClE,mEAA8D;AAE9D,SAAgB,uBAAuB,CACrC,MAAc,EACd,oBAA4B,EAC5B,UAAe;IAEf,IAEM,kBAAkB,GAFxB,MAEM,kBAAkB;QACtB,YAEW,eAAgC;YAAhC,oBAAe,GAAf,eAAe,CAAiB;QACxC,CAAC;QAGE,AAAN,KAAK,CAAC,SAAS;YACb,OAAO,2EAA2E,CAAC;QACrF,CAAC;QAIK,AAAN,KAAK,CAAC,KAAK,CAAY,GAAQ;YAE7B,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QAGD,YAAY,CAAS,MAAiC;YACpD,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;gBAC1B,MAAM,IAAI,4BAAmB,CAAC,kCAAkC,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QACjE,CAAC;QAIK,AAAN,KAAK,CAAC,UAAU,CAAY,GAAQ,IAAiB,CAAC;QAItD,kBAAkB,CAAY,GAAG;YAC/B,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;gBACd,MAAM,IAAI,8BAAqB,CAAC,6BAA6B,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/C,CAAC;QAIK,AAAN,KAAK,CAAC,aAAa;YACjB,OAAO,mBAAU,CAAC,EAAE,CAAC;QACvB,CAAC;QAIK,AAAN,KAAK,CAAC,qBAAqB,CAAY,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AAC,2CAAmB,CAAC;QAC/B,IAAA,mBAAU,EAAC,MAAM,CAAC;QAGd,WAAA,IAAA,eAAM,EAAC,oBAAoB,CAAC,CAAA;yCACH,kCAAe;OAHvC,kBAAkB,CA2DvB;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { Type } from "@nestjs/common";
2
+ export interface NestAuthModuleOptions {
3
+ UserModule: Type<any>;
4
+ UserService: Type<NestAuthInterface>;
5
+ jwtSecret: string;
6
+ jwtExpiresIn?: string;
7
+ jwtRefreshTokenExpiresIn?: string;
8
+ routePrefix?: string;
9
+ }
10
+ export type JwtPayloadType = {
11
+ sub: number | string;
12
+ name?: string;
13
+ email?: string;
14
+ username?: string;
15
+ role?: string;
16
+ pic?: string;
17
+ macId?: string;
18
+ [key: string]: number | string | boolean | undefined;
19
+ } | null;
20
+ export type SocialProfileType = {
21
+ id: string;
22
+ email: string;
23
+ firstName: string;
24
+ lastName: string;
25
+ picture: string;
26
+ accessToken: string;
27
+ refreshToken: string;
28
+ };
29
+ export type GoogleProfileType = SocialProfileType;
30
+ export type FacebookProfileType = SocialProfileType;
31
+ export interface NestAuthInterface {
32
+ validateUser(params: any): Promise<JwtPayloadType>;
33
+ getUserById(id: number | string): Promise<JwtPayloadType>;
34
+ google?(params: GoogleProfileType): Promise<JwtPayloadType>;
35
+ facebook?(params: FacebookProfileType): Promise<JwtPayloadType>;
36
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=nestauth.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nestauth.interface.js","sourceRoot":"","sources":["../../src/nestauth.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ import { NestAuthModuleOptions } from "./nestauth.interface";
3
+ export declare class NestAuthModule {
4
+ static forRoot(options: NestAuthModuleOptions): DynamicModule;
5
+ }
@@ -0,0 +1,96 @@
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 NestAuthModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.NestAuthModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const config_1 = require("@nestjs/config");
13
+ const nestauth_service_1 = require("./nestauth.service");
14
+ const nestauth_controller_1 = require("./nestauth.controller");
15
+ const passport_1 = require("@nestjs/passport");
16
+ const jwt_1 = require("@nestjs/jwt");
17
+ const nestauth_jwt_strategy_1 = require("./nestauth-jwt.strategy");
18
+ const nestauth_google_strategy_1 = require("./nestauth-google.strategy");
19
+ const nestauth_facebook_strategy_1 = require("./nestauth-facebook.strategy");
20
+ const nestauth_local_strategy_1 = require("./nestauth-local.strategy");
21
+ const nestauth_local_guard_1 = require("./nestauth-local.guard");
22
+ let NestAuthModule = NestAuthModule_1 = class NestAuthModule {
23
+ static forRoot(options) {
24
+ const JwtSecretProvider = {
25
+ provide: "JWT_SECRET",
26
+ useValue: options.jwtSecret || "60s",
27
+ };
28
+ const JwtExpiresInProvider = {
29
+ provide: "JWT_EXPIRES_IN",
30
+ useValue: options.jwtExpiresIn,
31
+ };
32
+ const JwtRefreshTokenExpiresInProvider = {
33
+ provide: "JWT_REFRESH_TOKEN_EXPIRES_IN",
34
+ useValue: options.jwtRefreshTokenExpiresIn,
35
+ };
36
+ const controllerPath = options.routePrefix
37
+ ? `${options.routePrefix.replace(/^\/|\/$/g, "")}/nestauth`
38
+ : "nestauth";
39
+ const pathKey = controllerPath.replaceAll("/", "_").toUpperCase();
40
+ const userServiceToken = `NEST_AUTH_USER_SERVICE_${pathKey}`;
41
+ const nestAuthServiceToken = `NEST_AUTH_SERVICE_${pathKey}`;
42
+ const strategyName = `${pathKey}-local`;
43
+ const LocalStrategy = (0, nestauth_local_strategy_1.createLocalStrategy)(strategyName, userServiceToken);
44
+ const LocalGuard = (0, nestauth_local_guard_1.createLocalGuard)(strategyName);
45
+ const controller = (0, nestauth_controller_1.createDynamicController)(controllerPath, nestAuthServiceToken, LocalGuard);
46
+ return {
47
+ module: NestAuthModule_1,
48
+ imports: [
49
+ jwt_1.JwtModule.registerAsync({
50
+ imports: [],
51
+ inject: [],
52
+ useFactory: async () => ({
53
+ secret: options.jwtSecret,
54
+ signOptions: {
55
+ expiresIn: options.jwtExpiresIn,
56
+ },
57
+ }),
58
+ }),
59
+ (0, common_1.forwardRef)(() => options.UserModule),
60
+ ],
61
+ providers: [
62
+ {
63
+ provide: userServiceToken,
64
+ useExisting: options.UserService,
65
+ },
66
+ {
67
+ provide: nestAuthServiceToken,
68
+ useFactory: (jwtService, userService, jwtExpiresIn, jwtRefreshTokenExpiresIn) => new nestauth_service_1.NestAuthService(jwtService, userService, jwtExpiresIn, jwtRefreshTokenExpiresIn),
69
+ inject: [
70
+ jwt_1.JwtService,
71
+ userServiceToken,
72
+ "JWT_EXPIRES_IN",
73
+ "JWT_REFRESH_TOKEN_EXPIRES_IN",
74
+ ],
75
+ },
76
+ nestauth_jwt_strategy_1.NestAuthJwtStrategy,
77
+ nestauth_google_strategy_1.NestAuthGoogleStrategy,
78
+ nestauth_facebook_strategy_1.NestAuthFacebookStrategy,
79
+ JwtSecretProvider,
80
+ JwtExpiresInProvider,
81
+ JwtRefreshTokenExpiresInProvider,
82
+ LocalStrategy,
83
+ LocalGuard,
84
+ ],
85
+ exports: [nestAuthServiceToken],
86
+ controllers: [controller],
87
+ };
88
+ }
89
+ };
90
+ exports.NestAuthModule = NestAuthModule;
91
+ exports.NestAuthModule = NestAuthModule = NestAuthModule_1 = __decorate([
92
+ (0, common_1.Module)({
93
+ imports: [passport_1.PassportModule, config_1.ConfigModule.forRoot({})],
94
+ })
95
+ ], NestAuthModule);
96
+ //# sourceMappingURL=nestauth.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nestauth.module.js","sourceRoot":"","sources":["../../src/nestauth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA6E;AAC7E,2CAA8C;AAC9C,yDAAqD;AACrD,+DAAgE;AAEhE,+CAAkD;AAClD,qCAAoD;AACpD,mEAA8D;AAE9D,yEAAoE;AACpE,6EAAwE;AAExE,uEAAgE;AAChE,iEAA0D;AAKnD,IAAM,cAAc,sBAApB,MAAM,cAAc;IACzB,MAAM,CAAC,OAAO,CAAC,OAA8B;QAC3C,MAAM,iBAAiB,GAAa;YAClC,OAAO,EAAE,YAAY;YACrB,QAAQ,EAAE,OAAO,CAAC,SAAS,IAAI,KAAK;SACrC,CAAC;QAEF,MAAM,oBAAoB,GAAa;YACrC,OAAO,EAAE,gBAAgB;YACzB,QAAQ,EAAE,OAAO,CAAC,YAAY;SAC/B,CAAC;QAEF,MAAM,gCAAgC,GAAa;YACjD,OAAO,EAAE,8BAA8B;YACvC,QAAQ,EAAE,OAAO,CAAC,wBAAwB;SAC3C,CAAC;QAEF,MAAM,cAAc,GAAG,OAAO,CAAC,WAAW;YACxC,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,WAAW;YAC3D,CAAC,CAAC,UAAU,CAAC;QAEf,MAAM,OAAO,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;QAElE,MAAM,gBAAgB,GAAG,0BAA0B,OAAO,EAAE,CAAC;QAC7D,MAAM,oBAAoB,GAAG,qBAAqB,OAAO,EAAE,CAAC;QAE5D,MAAM,YAAY,GAA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AAC;CACF,CAAA;AAxGY,wCAAc;yBAAd,cAAc;IAH1B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,yBAAc,EAAE,qBAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;KACpD,CAAC;GACW,cAAc,CAwG1B"}
@@ -0,0 +1,14 @@
1
+ import { FacebookProfileType, GoogleProfileType, NestAuthInterface } from "./nestauth.interface";
2
+ import { JwtService } from "@nestjs/jwt";
3
+ import { StringValue } from "ms";
4
+ export declare class NestAuthService {
5
+ private jwtService;
6
+ readonly userService: NestAuthInterface;
7
+ private readonly jwtExpiresIn;
8
+ private readonly jwtRefreshTokenExpiresIn;
9
+ constructor(jwtService: JwtService, userService: NestAuthInterface, jwtExpiresIn?: StringValue | number, jwtRefreshTokenExpiresIn?: StringValue | number);
10
+ login(user: any): Promise<any>;
11
+ google(user: GoogleProfileType): Promise<any>;
12
+ facebook(user: FacebookProfileType): Promise<any>;
13
+ refreshToken(refreshToken: string): Promise<any>;
14
+ }
@@ -0,0 +1,72 @@
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.NestAuthService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const jwt_1 = require("@nestjs/jwt");
18
+ let NestAuthService = class NestAuthService {
19
+ constructor(jwtService, userService, jwtExpiresIn = "15m", jwtRefreshTokenExpiresIn = "7d") {
20
+ this.jwtService = jwtService;
21
+ this.userService = userService;
22
+ this.jwtExpiresIn = jwtExpiresIn;
23
+ this.jwtRefreshTokenExpiresIn = jwtRefreshTokenExpiresIn;
24
+ }
25
+ async login(user) {
26
+ return {
27
+ accessToken: this.jwtService.sign(user, {
28
+ expiresIn: this.jwtExpiresIn || "15m",
29
+ }),
30
+ refreshToken: this.jwtService.sign(user, {
31
+ expiresIn: this.jwtRefreshTokenExpiresIn || "7d",
32
+ }),
33
+ accessTokenExpiresIn: this.jwtExpiresIn || "15m",
34
+ refreshTokenExpiresIn: this.jwtRefreshTokenExpiresIn || "7d",
35
+ };
36
+ }
37
+ async google(user) {
38
+ const payload = await this.userService.google(user);
39
+ if (!payload) {
40
+ throw new common_1.UnauthorizedException("Invalid credentials");
41
+ }
42
+ return this.login(payload);
43
+ }
44
+ async facebook(user) {
45
+ const payload = await this.userService.facebook(user);
46
+ if (!payload) {
47
+ throw new common_1.UnauthorizedException("Invalid credentials");
48
+ }
49
+ return this.login(payload);
50
+ }
51
+ async refreshToken(refreshToken) {
52
+ try {
53
+ const payload = this.jwtService.verify(refreshToken);
54
+ const user = await this.userService.getUserById(payload.sub);
55
+ if (!user) {
56
+ throw new common_1.UnauthorizedException("Invalid or expired refresh token");
57
+ }
58
+ return this.login(user);
59
+ }
60
+ catch (err) {
61
+ throw new common_1.UnauthorizedException("Invalid or expired refresh token");
62
+ }
63
+ }
64
+ };
65
+ exports.NestAuthService = NestAuthService;
66
+ exports.NestAuthService = NestAuthService = __decorate([
67
+ (0, common_1.Injectable)(),
68
+ __param(2, (0, common_1.Inject)("JWT_EXPIRES_IN")),
69
+ __param(3, (0, common_1.Inject)("JWT_REFRESH_TOKEN_EXPIRES_IN")),
70
+ __metadata("design:paramtypes", [jwt_1.JwtService, Object, Object, Object])
71
+ ], NestAuthService);
72
+ //# sourceMappingURL=nestauth.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nestauth.service.js","sourceRoot":"","sources":["../../src/nestauth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAO3E,qCAAyC;AAIlC,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB,YACY,UAAsB,EACrB,WAA8B,EAEtB,eAAqC,KAAK,EAE1C,2BAAiD,IAAI;QAL9D,eAAU,GAAV,UAAU,CAAY;QACrB,gBAAW,GAAX,WAAW,CAAmB;QAEtB,iBAAY,GAAZ,YAAY,CAA8B;QAE1C,6BAAwB,GAAxB,wBAAwB,CAA6B;IACvE,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,IAAS;QACjB,OAAO;YACH,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE;gBACpC,SAAS,EAAE,IAAI,CAAC,YAAY,IAAI,KAAK;aACxC,CAAC;YACF,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE;gBACrC,SAAS,EAAE,IAAI,CAAC,wBAAwB,IAAI,IAAI;aACnD,CAAC;YACF,oBAAoB,EAAE,IAAI,CAAC,YAAY,IAAI,KAAK;YAChD,qBAAqB,EAAE,IAAI,CAAC,wBAAwB,IAAI,IAAI;SAC/D,CAAC;IACN,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAuB;QAChC,MAAM,OAAO,GAAmB,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEpE,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,8BAAqB,CAAC,qBAAqB,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAyB;QACpC,MAAM,OAA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