@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
@@ -1,16 +1,16 @@
1
1
  import {
2
- Request,
3
- Controller,
4
- Get,
5
- Post,
6
- UseGuards,
7
- Body,
8
- UnauthorizedException,
9
- HttpStatus,
10
- All,
11
- BadRequestException,
12
- UseFilters,
13
- Inject,
2
+ Request,
3
+ Controller,
4
+ Get,
5
+ Post,
6
+ UseGuards,
7
+ Body,
8
+ UnauthorizedException,
9
+ HttpStatus,
10
+ All,
11
+ BadRequestException,
12
+ UseFilters,
13
+ Inject,
14
14
  } from "@nestjs/common";
15
15
  import { NestAuthService } from "./nestauth.service";
16
16
  import { NestAuthGoogleGuard } from "./nestauth-google.guard";
@@ -18,76 +18,72 @@ import { NestAuthFacebookGuard } from "./nestauth-facebook.guard";
18
18
  import { HttpExceptionFilter } from "./http-exception.filter";
19
19
 
20
20
  export function createDynamicController(
21
- prefix: string,
22
- nestAuthServiceToken: string,
23
- localGuard: any,
21
+ prefix: string,
22
+ nestAuthServiceToken: string,
23
+ localGuard: any,
24
24
  ) {
25
- @UseFilters(HttpExceptionFilter)
26
- @Controller(prefix)
27
- class NestAuthController {
28
- constructor(
29
- @Inject(nestAuthServiceToken)
30
- readonly nestAuthService: NestAuthService,
31
- ) {}
25
+ @UseFilters(HttpExceptionFilter)
26
+ @Controller(prefix)
27
+ class NestAuthController {
28
+ constructor(
29
+ @Inject(nestAuthServiceToken)
30
+ readonly nestAuthService: NestAuthService,
31
+ ) {}
32
32
 
33
- @All()
34
- async greetings(): Promise<string> {
35
- return "Welcome to NestAuth. Please check our documentation for more information.";
36
- }
33
+ @All()
34
+ async greetings(): Promise<string> {
35
+ return "Welcome to NestAuth. Please check our documentation for more information.";
36
+ }
37
37
 
38
- @UseGuards(localGuard)
39
- @Post("login")
40
- async login(@Request() req: any): Promise<any> {
41
- console.log("nestAuthServiceToken", nestAuthServiceToken);
42
- return this.nestAuthService.login(req.user);
43
- }
38
+ @UseGuards(localGuard)
39
+ @Post("login")
40
+ async login(@Request() req: any): Promise<any> {
41
+ // console.log("nestAuthServiceToken", nestAuthServiceToken);
42
+ return this.nestAuthService.login(req.user);
43
+ }
44
44
 
45
- @Post("refresh-token")
46
- refreshToken(@Body() params: { refresh_token: string }): Promise<any> {
47
- if (!params.refresh_token) {
48
- throw new BadRequestException(
49
- "Invalid or expired refresh token",
50
- );
51
- }
52
- return this.nestAuthService.refreshToken(params.refresh_token);
53
- }
45
+ @Post("refresh-token")
46
+ refreshToken(@Body() params: { refresh_token: string }): Promise<any> {
47
+ if (!params.refresh_token) {
48
+ throw new BadRequestException("Invalid or expired refresh token");
49
+ }
50
+ return this.nestAuthService.refreshToken(params.refresh_token);
51
+ }
54
52
 
55
- @UseGuards(NestAuthGoogleGuard)
56
- @Get("google")
57
- async googleAuth(@Request() req: any): Promise<any> {}
53
+ @UseGuards(NestAuthGoogleGuard)
54
+ @Get("google")
55
+ async googleAuth(@Request() req: any): Promise<any> {}
58
56
 
59
- @Get("google-redirect")
60
- @UseGuards(NestAuthGoogleGuard)
61
- googleAuthRedirect(@Request() req) {
62
- if (!req.user) {
63
- throw new UnauthorizedException("Unable to login with Google");
64
- }
65
- return this.nestAuthService.google(req.user);
66
- }
57
+ @Get("google-redirect")
58
+ @UseGuards(NestAuthGoogleGuard)
59
+ googleAuthRedirect(@Request() req) {
60
+ if (!req.user) {
61
+ throw new UnauthorizedException("Unable to login with Google");
62
+ }
63
+ return this.nestAuthService.google(req.user);
64
+ }
67
65
 
68
- @Get("/facebook")
69
- @UseGuards(NestAuthFacebookGuard)
70
- async facebookLogin(): Promise<any> {
71
- return HttpStatus.OK;
72
- }
66
+ @Get("/facebook")
67
+ @UseGuards(NestAuthFacebookGuard)
68
+ async facebookLogin(): Promise<any> {
69
+ return HttpStatus.OK;
70
+ }
73
71
 
74
- @Get("/facebook-redirect")
75
- @UseGuards(NestAuthFacebookGuard)
76
- async facebookLoginRedirect(@Request() req): Promise<any> {
77
- if (!req.user) {
78
- throw new UnauthorizedException(
79
- "Unable to login with Facebook",
80
- );
81
- }
82
- return this.nestAuthService.facebook(req.user);
83
- }
72
+ @Get("/facebook-redirect")
73
+ @UseGuards(NestAuthFacebookGuard)
74
+ async facebookLoginRedirect(@Request() req): Promise<any> {
75
+ if (!req.user) {
76
+ throw new UnauthorizedException("Unable to login with Facebook");
77
+ }
78
+ return this.nestAuthService.facebook(req.user);
79
+ }
84
80
 
85
- @UseGuards(localGuard)
86
- @Get("logout")
87
- async logout(@Request() req: any) {
88
- return req.logout();
89
- }
81
+ @UseGuards(localGuard)
82
+ @Get("logout")
83
+ async logout(@Request() req: any) {
84
+ return req.logout();
90
85
  }
86
+ }
91
87
 
92
- return NestAuthController;
88
+ return NestAuthController;
93
89
  }
@@ -14,115 +14,110 @@ import { createLocalStrategy } from "./nestauth-local.strategy";
14
14
  import { createLocalGuard } from "./nestauth-local.guard";
15
15
 
16
16
  @Module({
17
- imports: [PassportModule, ConfigModule.forRoot({})],
17
+ imports: [PassportModule, ConfigModule.forRoot({})],
18
18
  })
19
19
  export class NestAuthModule {
20
- static forRoot(options: NestAuthModuleOptions): DynamicModule {
21
- const JwtSecretProvider: Provider = {
22
- provide: "JWT_SECRET",
23
- useValue: options.jwtSecret || "60s",
24
- };
20
+ static forRoot(options: NestAuthModuleOptions): DynamicModule {
21
+ const JwtSecretProvider: Provider = {
22
+ provide: "JWT_SECRET",
23
+ useValue: options.jwtSecret || "60s",
24
+ };
25
25
 
26
- const JwtExpiresInProvider: Provider = {
27
- provide: "JWT_EXPIRES_IN",
28
- useValue: options.jwtExpiresIn,
29
- };
26
+ const JwtExpiresInProvider: Provider = {
27
+ provide: "JWT_EXPIRES_IN",
28
+ useValue: options.jwtExpiresIn,
29
+ };
30
30
 
31
- const JwtRefreshTokenExpiresInProvider: Provider = {
32
- provide: "JWT_REFRESH_TOKEN_EXPIRES_IN",
33
- useValue: options.jwtRefreshTokenExpiresIn,
34
- };
31
+ const JwtRefreshTokenExpiresInProvider: Provider = {
32
+ provide: "JWT_REFRESH_TOKEN_EXPIRES_IN",
33
+ useValue: options.jwtRefreshTokenExpiresIn,
34
+ };
35
35
 
36
- const controllerPath = options.routePrefix
37
- ? `${options.routePrefix.replace(/^\/|\/$/g, "")}/nestauth`
38
- : "nestauth";
36
+ const controllerPath = options.routePrefix
37
+ ? `${options.routePrefix.replace(/^\/|\/$/g, "")}/nestauth`
38
+ : "nestauth";
39
39
 
40
- const pathKey = controllerPath.replaceAll("/", "_").toUpperCase();
40
+ const pathKey = controllerPath.replaceAll("/", "_").toUpperCase();
41
41
 
42
- const userServiceToken = `NEST_AUTH_USER_SERVICE_${pathKey}`;
43
- const nestAuthServiceToken = `NEST_AUTH_SERVICE_${pathKey}`;
42
+ const userServiceToken = `NEST_AUTH_USER_SERVICE_${pathKey}`;
43
+ const nestAuthServiceToken = `NEST_AUTH_SERVICE_${pathKey}`;
44
44
 
45
- const strategyName = `${pathKey}-local`;
45
+ const strategyName = `${pathKey}-local`;
46
46
 
47
- const LocalStrategy = createLocalStrategy(
48
- strategyName,
49
- userServiceToken,
50
- );
47
+ const LocalStrategy = createLocalStrategy(strategyName, userServiceToken);
51
48
 
52
- const LocalGuard = createLocalGuard(strategyName);
49
+ const LocalGuard = createLocalGuard(strategyName);
53
50
 
54
- console.log("controllerPath", controllerPath);
55
- console.log("pathKey", pathKey);
56
- console.log("userServiceToken", userServiceToken);
57
- console.log("nestAuthServiceToken", nestAuthServiceToken);
51
+ // console.log("controllerPath", controllerPath);
52
+ // console.log("pathKey", pathKey);
53
+ // console.log("userServiceToken", userServiceToken);
54
+ // console.log("nestAuthServiceToken", nestAuthServiceToken);
58
55
 
59
- console.log("------------------------------------------");
56
+ // console.log("------------------------------------------");
60
57
 
61
- const controller = createDynamicController(
62
- controllerPath,
63
- nestAuthServiceToken,
64
- LocalGuard,
65
- );
58
+ const controller = createDynamicController(
59
+ controllerPath,
60
+ nestAuthServiceToken,
61
+ LocalGuard,
62
+ );
66
63
 
67
- return {
68
- module: NestAuthModule,
69
- imports: [
70
- JwtModule.registerAsync({
71
- imports: [],
72
- inject: [],
73
- useFactory: async () => ({
74
- secret: options.jwtSecret,
75
- signOptions: {
76
- expiresIn: options.jwtExpiresIn as
77
- | StringValue
78
- | number,
79
- },
80
- }),
81
- }),
82
- forwardRef(() => options.UserModule),
83
- ],
84
- providers: [
85
- {
86
- provide: userServiceToken,
87
- useExisting: options.UserService,
88
- },
89
- {
90
- provide: nestAuthServiceToken,
91
- useFactory: (
92
- jwtService: JwtService,
93
- userService: NestAuthInterface,
94
- jwtExpiresIn: StringValue | number,
95
- jwtRefreshTokenExpiresIn: StringValue | number,
96
- ) =>
97
- new NestAuthService(
98
- jwtService,
99
- userService,
100
- jwtExpiresIn,
101
- jwtRefreshTokenExpiresIn,
102
- ),
103
- inject: [
104
- JwtService,
105
- userServiceToken,
106
- "JWT_EXPIRES_IN",
107
- "JWT_REFRESH_TOKEN_EXPIRES_IN",
108
- ],
109
- },
110
- NestAuthJwtStrategy,
111
- NestAuthGoogleStrategy,
112
- NestAuthFacebookStrategy,
113
- JwtSecretProvider,
114
- JwtExpiresInProvider,
115
- JwtRefreshTokenExpiresInProvider,
116
- LocalStrategy,
117
- LocalGuard,
64
+ return {
65
+ module: NestAuthModule,
66
+ imports: [
67
+ JwtModule.registerAsync({
68
+ imports: [],
69
+ inject: [],
70
+ useFactory: async () => ({
71
+ secret: options.jwtSecret,
72
+ signOptions: {
73
+ expiresIn: options.jwtExpiresIn as StringValue | number,
74
+ },
75
+ }),
76
+ }),
77
+ forwardRef(() => options.UserModule),
78
+ ],
79
+ providers: [
80
+ {
81
+ provide: userServiceToken,
82
+ useExisting: options.UserService,
83
+ },
84
+ {
85
+ provide: nestAuthServiceToken,
86
+ useFactory: (
87
+ jwtService: JwtService,
88
+ userService: NestAuthInterface,
89
+ jwtExpiresIn: StringValue | number,
90
+ jwtRefreshTokenExpiresIn: StringValue | number,
91
+ ) =>
92
+ new NestAuthService(
93
+ jwtService,
94
+ userService,
95
+ jwtExpiresIn,
96
+ jwtRefreshTokenExpiresIn,
97
+ ),
98
+ inject: [
99
+ JwtService,
100
+ userServiceToken,
101
+ "JWT_EXPIRES_IN",
102
+ "JWT_REFRESH_TOKEN_EXPIRES_IN",
103
+ ],
104
+ },
105
+ NestAuthJwtStrategy,
106
+ NestAuthGoogleStrategy,
107
+ NestAuthFacebookStrategy,
108
+ JwtSecretProvider,
109
+ JwtExpiresInProvider,
110
+ JwtRefreshTokenExpiresInProvider,
111
+ LocalStrategy,
112
+ LocalGuard,
118
113
 
119
- // {
120
- // provide: APP_FILTER,
121
- // useClass: HttpExceptionFilter,
122
- // },
123
- ],
124
- exports: [nestAuthServiceToken],
125
- controllers: [controller],
126
- };
127
- }
114
+ // {
115
+ // provide: APP_FILTER,
116
+ // useClass: HttpExceptionFilter,
117
+ // },
118
+ ],
119
+ exports: [nestAuthServiceToken],
120
+ controllers: [controller],
121
+ };
122
+ }
128
123
  }