@next-nest-auth/nestauth 0.0.5
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/LICENSE +21 -0
- package/README.md +166 -0
- package/dist/global-exception.filter.d.ts +4 -0
- package/dist/global-exception.filter.js +30 -0
- package/dist/global-exception.filter.js.map +1 -0
- package/dist/http-exception.filter.d.ts +4 -0
- package/dist/http-exception.filter.js +37 -0
- package/dist/http-exception.filter.js.map +1 -0
- package/dist/http.exception.filter.d.ts +4 -0
- package/dist/http.exception.filter.js +29 -0
- package/dist/http.exception.filter.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt-auth.guard.d.ts +4 -0
- package/dist/jwt-auth.guard.js +18 -0
- package/dist/jwt-auth.guard.js.map +1 -0
- package/dist/jwt.guard.d.ts +4 -0
- package/dist/jwt.guard.js +18 -0
- package/dist/jwt.guard.js.map +1 -0
- package/dist/jwt.strategy.d.ts +12 -0
- package/dist/jwt.strategy.js +37 -0
- package/dist/jwt.strategy.js.map +1 -0
- package/dist/local-auth.guard.d.ts +4 -0
- package/dist/local-auth.guard.js +18 -0
- package/dist/local-auth.guard.js.map +1 -0
- package/dist/local.srategy.d.ts +9 -0
- package/dist/local.srategy.js +33 -0
- package/dist/local.srategy.js.map +1 -0
- package/dist/local.strategy.d.ts +11 -0
- package/dist/local.strategy.js +42 -0
- package/dist/local.strategy.js.map +1 -0
- package/dist/nestauth/nestauth.controller.d.ts +2 -0
- package/dist/nestauth/nestauth.controller.js +17 -0
- package/dist/nestauth/nestauth.controller.js.map +1 -0
- package/dist/nestauth/nestauth.controller.spec.d.ts +1 -0
- package/dist/nestauth/nestauth.controller.spec.js +17 -0
- package/dist/nestauth/nestauth.controller.spec.js.map +1 -0
- package/dist/nestauth-facebook.guard.d.ts +7 -0
- package/dist/nestauth-facebook.guard.js +29 -0
- package/dist/nestauth-facebook.guard.js.map +1 -0
- package/dist/nestauth-facebook.strategy.d.ts +9 -0
- package/dist/nestauth-facebook.strategy.js +45 -0
- package/dist/nestauth-facebook.strategy.js.map +1 -0
- package/dist/nestauth-google.guard.d.ts +7 -0
- package/dist/nestauth-google.guard.js +29 -0
- package/dist/nestauth-google.guard.js.map +1 -0
- package/dist/nestauth-google.strategy.d.ts +9 -0
- package/dist/nestauth-google.strategy.js +44 -0
- package/dist/nestauth-google.strategy.js.map +1 -0
- package/dist/nestauth-jwt.guard.d.ts +6 -0
- package/dist/nestauth-jwt.guard.js +32 -0
- package/dist/nestauth-jwt.guard.js.map +1 -0
- package/dist/nestauth-jwt.strategy.d.ts +18 -0
- package/dist/nestauth-jwt.strategy.js +45 -0
- package/dist/nestauth-jwt.strategy.js.map +1 -0
- package/dist/nestauth-local.guard.d.ts +4 -0
- package/dist/nestauth-local.guard.js +18 -0
- package/dist/nestauth-local.guard.js.map +1 -0
- package/dist/nestauth-local.strategy.d.ts +11 -0
- package/dist/nestauth-local.strategy.js +40 -0
- package/dist/nestauth-local.strategy.js.map +1 -0
- package/dist/nestauth.controller.d.ts +15 -0
- package/dist/nestauth.controller.js +119 -0
- package/dist/nestauth.controller.js.map +1 -0
- package/dist/nestauth.guard.d.ts +4 -0
- package/dist/nestauth.guard.js +18 -0
- package/dist/nestauth.guard.js.map +1 -0
- package/dist/nestauth.interface.d.ts +32 -0
- package/dist/nestauth.interface.js +3 -0
- package/dist/nestauth.interface.js.map +1 -0
- package/dist/nestauth.module.d.ts +5 -0
- package/dist/nestauth.module.js +81 -0
- package/dist/nestauth.module.js.map +1 -0
- package/dist/nestauth.service.d.ts +13 -0
- package/dist/nestauth.service.js +71 -0
- package/dist/nestauth.service.js.map +1 -0
- package/dist/nestauth.strategy.d.ts +11 -0
- package/dist/nestauth.strategy.js +38 -0
- package/dist/nestauth.strategy.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +61 -0
- package/src/http-exception.filter.ts +33 -0
- package/src/index.ts +4 -0
- package/src/nestauth-facebook.guard.ts +12 -0
- package/src/nestauth-facebook.strategy.ts +39 -0
- package/src/nestauth-google.guard.ts +12 -0
- package/src/nestauth-google.strategy.ts +39 -0
- package/src/nestauth-jwt.guard.ts +24 -0
- package/src/nestauth-jwt.strategy.ts +27 -0
- package/src/nestauth-local.guard.ts +5 -0
- package/src/nestauth-local.strategy.ts +26 -0
- package/src/nestauth.controller.ts +70 -0
- package/src/nestauth.interface.ts +37 -0
- package/src/nestauth.module.ts +73 -0
- package/src/nestauth.service.ts +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Md Shafkat Hussain Tanvir
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# NestJS Authentication with @next-nest-auth/nestauth
|
|
2
|
+
|
|
3
|
+
This README provides instructions to set up authentication in a NestJS application using the `@next-nest-auth/nestauth` package.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js and npm installed on your machine
|
|
8
|
+
- NestJS application set up
|
|
9
|
+
|
|
10
|
+
## Installation Instructions
|
|
11
|
+
|
|
12
|
+
### 1. Install NestJS Application
|
|
13
|
+
|
|
14
|
+
If you haven't already created a NestJS application, you can create one using the NestJS CLI:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm i -g @nestjs/cli
|
|
18
|
+
nest new nestauth-app
|
|
19
|
+
cd nestauth-app
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Install `@next-nest-auth/nestauth` Package
|
|
23
|
+
|
|
24
|
+
Next, install the `@next-nest-auth/nestauth` package:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @next-nest-auth/nestauth
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 3. Load `NestAuthModule` in the App
|
|
31
|
+
|
|
32
|
+
Import and register `NestAuthModule` in your application's module.
|
|
33
|
+
|
|
34
|
+
Edit `app.module.ts` to add `NestAuthModule`:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { Module } from "@nestjs/common";
|
|
38
|
+
import { NestAuthModule } from "@next-nest-auth/nestauth";
|
|
39
|
+
import { UserService } from "./user.service";
|
|
40
|
+
|
|
41
|
+
@Module({
|
|
42
|
+
imports: [
|
|
43
|
+
NestAuthModule.register({
|
|
44
|
+
UserService: UserService,
|
|
45
|
+
jwtSecret: process.env.JWT_SECRET || "my-secret-key",
|
|
46
|
+
jwtExpiresIn: "1h", // Set the expiration time for the JWT
|
|
47
|
+
}),
|
|
48
|
+
],
|
|
49
|
+
providers: [UserService],
|
|
50
|
+
})
|
|
51
|
+
export class AppModule {}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 4. Create the `UserService`
|
|
55
|
+
|
|
56
|
+
Create a `UserService` that implements `NestAuthInterface`. This service will handle user authentication and the process for validating user credentials, integrating third-party services like Google and Facebook.
|
|
57
|
+
|
|
58
|
+
Create a new file `user.service.ts` and add the following code:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { Injectable } from "@nestjs/common";
|
|
62
|
+
import {
|
|
63
|
+
JwtPayloadType,
|
|
64
|
+
NestAuthInterface,
|
|
65
|
+
} from "@next-nest-auth/nestauth/dist/nestauth.interface";
|
|
66
|
+
|
|
67
|
+
@Injectable()
|
|
68
|
+
export class UserService implements NestAuthInterface {
|
|
69
|
+
constructor() {}
|
|
70
|
+
|
|
71
|
+
async validateUser(params: any): Promise<JwtPayloadType> {
|
|
72
|
+
// Simulate user authentication, usually done by checking password against database
|
|
73
|
+
return {
|
|
74
|
+
sub: 1,
|
|
75
|
+
name: "John Doe",
|
|
76
|
+
email: "QlLZL@example.com",
|
|
77
|
+
role: "user",
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 5. Test the Installation
|
|
84
|
+
|
|
85
|
+
To test if the installation is successful, call POST -> `http://localhost:3000/nestauth/login` with your username/password or any params like mobile number/otp. It will generate and return access_token
|
|
86
|
+
|
|
87
|
+
#### example response
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
{
|
|
91
|
+
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsIm5hbWUiOiJKb2huIERvZSIsImVtYWlsIjoiUWxMWkxAZXhhbXBsZS5jb20iLCJyb2xlIjoidXNlciIsIm1hY0lkIjoiMDI6NDI6YTQ6NGM6MjU6YjgiLCJpYXQiOjE3Mzg1NTgyMDQsImV4cCI6MTczODU2MTgwNH0.8RtsLfhIMwWXloT65UgCHOaDyZaVkXxcS1ER6hpZ9H4",
|
|
92
|
+
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsIm5hbWUiOiJKb2huIERvZSIsImVtYWlsIjoiUWxMWkxAZXhhbXBsZS5jb20iLCJyb2xlIjoidXNlciIsIm1hY0lkIjoiMDI6NDI6YTQ6NGM6MjU6YjgiLCJpYXQiOjE3Mzg1NTgyMDQsImV4cCI6MTczOTE2MzAwNH0.eP70K-0Dyh-hPO1GcKoMugmxxt8TCR4thh_NHZfgG50",
|
|
93
|
+
"accessTokenExpiresIn": "1h",
|
|
94
|
+
"refreshTokenExpiresIn": "7d"
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 6 Refresh tokens
|
|
99
|
+
|
|
100
|
+
To refresh your token call GET -> `http://localhost:3000/nestauth/refresh_token` with your params `refresh_token` with value `your-refresh-token`
|
|
101
|
+
|
|
102
|
+
#### On Success
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
{
|
|
106
|
+
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsIm5hbWUiOiJKb2huIERvZSIsImVtYWlsIjoiUWxMWkxAZXhhbXBsZS5jb20iLCJyb2xlIjoidXNlciIsImlhdCI6MTczODU1OTQ0NCwiZXhwIjoxNzM4NTYzMDQ0fQ.l1aNl4s6f4KciTL7UGpKpTT_0RgQG51UJPi57GPcv9g",
|
|
107
|
+
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsIm5hbWUiOiJKb2huIERvZSIsImVtYWlsIjoiUWxMWkxAZXhhbXBsZS5jb20iLCJyb2xlIjoidXNlciIsImlhdCI6MTczODU1OTQ0NCwiZXhwIjoxNzM5MTY0MjQ0fQ.RQbGBBiwOR6VT7632VSGvN2j0SLdjLc_dTksyWswB3s",
|
|
108
|
+
"accessTokenExpiresIn": "1h",
|
|
109
|
+
"refreshTokenExpiresIn": "7d"
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### On failed
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
{
|
|
117
|
+
"statusCode": 401,
|
|
118
|
+
"message": "Invalid or expired refresh token",
|
|
119
|
+
"path": "/nestauth/refresh-token",
|
|
120
|
+
"app": "nestauth"
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 7. Protect Routes Using Guards
|
|
125
|
+
|
|
126
|
+
You can now protect routes using the `NestAuthJwtGuard`. For example, to protect a route that returns user profile information:
|
|
127
|
+
|
|
128
|
+
Edit the `app.controller.ts` or your desired controller:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { Controller, Get, UseGuards, Request } from "@nestjs/common";
|
|
132
|
+
import { NestAuthJwtGuard } from "@next-nest-auth/nestauth";
|
|
133
|
+
|
|
134
|
+
@Controller("user")
|
|
135
|
+
export class AppController {
|
|
136
|
+
@Get("/profile")
|
|
137
|
+
@UseGuards(NestAuthJwtGuard)
|
|
138
|
+
getProfile(@Request() req) {
|
|
139
|
+
return req.user;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Now your NestJS app will be set up with authentication using `@next-nest-auth/nestauth`. You can protect routes with the `NestAuthJwtGuard` and handle user authentication, JWT management.
|
|
145
|
+
|
|
146
|
+
### 7. Environment Variables
|
|
147
|
+
|
|
148
|
+
Don't forget to add the `JWT_SECRET` environment variable in your `.env` file:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
JWT_SECRET=my-secret-key
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Summary
|
|
157
|
+
|
|
158
|
+
This README has guided you through:
|
|
159
|
+
|
|
160
|
+
1. Installing the `@next-nest-auth/nestauth` package.
|
|
161
|
+
2. Registering the `NestAuthModule` in your `AppModule`.
|
|
162
|
+
3. Creating a custom `UserService` to handle user authentication.
|
|
163
|
+
4. Protecting routes with the `NestAuthJwtGuard`.
|
|
164
|
+
5. Testing the authentication setup.
|
|
165
|
+
|
|
166
|
+
You now have a basic NestJS app with JWT authentication ready to use. Feel free to extend this with additional authentication strategies like OAuth, refresh tokens, and more!
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.GlobalExceptionFilter = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let GlobalExceptionFilter = class GlobalExceptionFilter {
|
|
12
|
+
catch(exception, host) {
|
|
13
|
+
const ctx = host.switchToHttp();
|
|
14
|
+
const response = ctx.getResponse();
|
|
15
|
+
const request = ctx.getRequest();
|
|
16
|
+
const status = exception instanceof common_1.HttpException ? exception.getStatus() : 500;
|
|
17
|
+
const message = exception.message;
|
|
18
|
+
response.status(status).json({
|
|
19
|
+
statusCode: status,
|
|
20
|
+
message: message,
|
|
21
|
+
path: request.url,
|
|
22
|
+
app: "nestauth",
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.GlobalExceptionFilter = GlobalExceptionFilter;
|
|
27
|
+
exports.GlobalExceptionFilter = GlobalExceptionFilter = __decorate([
|
|
28
|
+
(0, common_1.Catch)()
|
|
29
|
+
], GlobalExceptionFilter);
|
|
30
|
+
//# sourceMappingURL=global-exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-exception.filter.js","sourceRoot":"","sources":["../src/global-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAKwB;AAIjB,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAC9B,KAAK,CAAC,SAAkB,EAAE,IAAmB;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAY,CAAC;QAC7C,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAW,CAAC;QAC1C,MAAM,MAAM,GACR,SAAS,YAAY,sBAAa,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QACrE,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;QAElC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YACzB,UAAU,EAAE,MAAM;YAClB,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,OAAO,CAAC,GAAG;YACjB,GAAG,EAAE,UAAU;SAClB,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AAhBY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,cAAK,GAAE;GACK,qBAAqB,CAgBjC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpExceptionFilter = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let HttpExceptionFilter = class HttpExceptionFilter {
|
|
12
|
+
catch(exception, host) {
|
|
13
|
+
const ctx = host.switchToHttp();
|
|
14
|
+
const response = ctx.getResponse();
|
|
15
|
+
const request = ctx.getRequest();
|
|
16
|
+
let status = 500;
|
|
17
|
+
let message = "Internal Server Error";
|
|
18
|
+
if (exception instanceof common_1.HttpException) {
|
|
19
|
+
status = exception.getStatus();
|
|
20
|
+
message = exception.message;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
console.error("Unexpected error:", exception);
|
|
24
|
+
}
|
|
25
|
+
response.status(status).json({
|
|
26
|
+
statusCode: status,
|
|
27
|
+
message: message,
|
|
28
|
+
path: request.url,
|
|
29
|
+
app: "nestauth",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.HttpExceptionFilter = HttpExceptionFilter;
|
|
34
|
+
exports.HttpExceptionFilter = HttpExceptionFilter = __decorate([
|
|
35
|
+
(0, common_1.Catch)()
|
|
36
|
+
], HttpExceptionFilter);
|
|
37
|
+
//# sourceMappingURL=http-exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-exception.filter.js","sourceRoot":"","sources":["../src/http-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAKwB;AAIjB,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC5B,KAAK,CAAC,SAAc,EAAE,IAAmB;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAY,CAAC;QAC7C,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAW,CAAC;QAE1C,IAAI,MAAM,GAAG,GAAG,CAAC;QACjB,IAAI,OAAO,GAAG,uBAAuB,CAAC;QAEtC,IAAI,SAAS,YAAY,sBAAa,EAAE,CAAC;YACrC,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;YAC/B,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;QAChC,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC;QAClD,CAAC;QAED,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YACzB,UAAU,EAAE,MAAM;YAClB,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,OAAO,CAAC,GAAG;YACjB,GAAG,EAAE,UAAU;SAClB,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AAvBY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,cAAK,GAAE;GACK,mBAAmB,CAuB/B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpExceptionFilter = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let HttpExceptionFilter = class HttpExceptionFilter {
|
|
12
|
+
catch(exception, host) {
|
|
13
|
+
const ctx = host.switchToHttp();
|
|
14
|
+
const response = ctx.getResponse();
|
|
15
|
+
const request = ctx.getRequest();
|
|
16
|
+
const status = exception.getStatus();
|
|
17
|
+
const message = exception.getResponse();
|
|
18
|
+
response.status(status).json({
|
|
19
|
+
statusCode: status,
|
|
20
|
+
message: message,
|
|
21
|
+
path: request.url,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.HttpExceptionFilter = HttpExceptionFilter;
|
|
26
|
+
exports.HttpExceptionFilter = HttpExceptionFilter = __decorate([
|
|
27
|
+
(0, common_1.Catch)(common_1.HttpException)
|
|
28
|
+
], HttpExceptionFilter);
|
|
29
|
+
//# sourceMappingURL=http.exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.exception.filter.js","sourceRoot":"","sources":["../src/http.exception.filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAKwB;AAIjB,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC5B,KAAK,CAAC,SAAwB,EAAE,IAAmB;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAY,CAAC;QAC7C,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAW,CAAC;QAC1C,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;QAExC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YACzB,UAAU,EAAE,MAAM;YAClB,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,OAAO,CAAC,GAAG;SACpB,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AAdY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,cAAK,EAAC,sBAAa,CAAC;GACR,mBAAmB,CAc/B"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./nestauth.module"), exports);
|
|
18
|
+
__exportStar(require("./nestauth.service"), exports);
|
|
19
|
+
__exportStar(require("./nestauth.interface"), exports);
|
|
20
|
+
__exportStar(require("./nestauth-jwt.guard"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,qDAAmC;AACnC,uDAAqC;AACrC,uDAAqC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.JwtAuthGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const passport_1 = require("@nestjs/passport");
|
|
12
|
+
let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)("jwt") {
|
|
13
|
+
};
|
|
14
|
+
exports.JwtAuthGuard = JwtAuthGuard;
|
|
15
|
+
exports.JwtAuthGuard = JwtAuthGuard = __decorate([
|
|
16
|
+
(0, common_1.Injectable)()
|
|
17
|
+
], JwtAuthGuard);
|
|
18
|
+
//# sourceMappingURL=jwt-auth.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-auth.guard.js","sourceRoot":"","sources":["../src/jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA6C;AAGtC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,IAAA,oBAAS,EAAC,KAAK,CAAC;CAAG,CAAA;AAAxC,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;GACA,YAAY,CAA4B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.NestAuthJwtAuthGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const passport_1 = require("@nestjs/passport");
|
|
12
|
+
let NestAuthJwtAuthGuard = class NestAuthJwtAuthGuard extends (0, passport_1.AuthGuard)("jwt") {
|
|
13
|
+
};
|
|
14
|
+
exports.NestAuthJwtAuthGuard = NestAuthJwtAuthGuard;
|
|
15
|
+
exports.NestAuthJwtAuthGuard = NestAuthJwtAuthGuard = __decorate([
|
|
16
|
+
(0, common_1.Injectable)()
|
|
17
|
+
], NestAuthJwtAuthGuard);
|
|
18
|
+
//# sourceMappingURL=jwt.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.guard.js","sourceRoot":"","sources":["../src/jwt.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA6C;AAGtC,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,IAAA,oBAAS,EAAC,KAAK,CAAC;CAAG,CAAA;AAAhD,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CAA4B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Strategy } from "passport-jwt";
|
|
2
|
+
declare const JwtStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithoutRequest] | [opt: import("passport-jwt").StrategyOptionsWithRequest]) => Strategy & {
|
|
3
|
+
validate(...args: any[]): unknown;
|
|
4
|
+
};
|
|
5
|
+
export declare class JwtStrategy extends JwtStrategy_base {
|
|
6
|
+
constructor(jwtSecret: string);
|
|
7
|
+
validate(payload: any): Promise<{
|
|
8
|
+
userId: any;
|
|
9
|
+
username: any;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
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.JwtStrategy = void 0;
|
|
16
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
17
|
+
const passport_1 = require("@nestjs/passport");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
|
|
20
|
+
constructor(jwtSecret) {
|
|
21
|
+
super({
|
|
22
|
+
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
23
|
+
ignoreExpiration: false,
|
|
24
|
+
secretOrKey: jwtSecret,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async validate(payload) {
|
|
28
|
+
return { userId: payload.sub, username: payload.username };
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.JwtStrategy = JwtStrategy;
|
|
32
|
+
exports.JwtStrategy = JwtStrategy = __decorate([
|
|
33
|
+
(0, common_1.Injectable)(),
|
|
34
|
+
__param(0, (0, common_1.Inject)("JWT_SECRET")),
|
|
35
|
+
__metadata("design:paramtypes", [String])
|
|
36
|
+
], JwtStrategy);
|
|
37
|
+
//# sourceMappingURL=jwt.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.strategy.js","sourceRoot":"","sources":["../src/jwt.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAoD;AACpD,+CAAoD;AACpD,2CAAoD;AAG7C,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IACvD,YAAkC,SAAiB;QAC/C,KAAK,CAAC;YACF,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,SAAS;SACzB,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAY;QACvB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC/D,CAAC;CACJ,CAAA;AAZY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAEI,WAAA,IAAA,eAAM,EAAC,YAAY,CAAC,CAAA;;GADxB,WAAW,CAYvB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LocalAuthGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const passport_1 = require("@nestjs/passport");
|
|
12
|
+
let LocalAuthGuard = class LocalAuthGuard extends (0, passport_1.AuthGuard)("local") {
|
|
13
|
+
};
|
|
14
|
+
exports.LocalAuthGuard = LocalAuthGuard;
|
|
15
|
+
exports.LocalAuthGuard = LocalAuthGuard = __decorate([
|
|
16
|
+
(0, common_1.Injectable)()
|
|
17
|
+
], LocalAuthGuard);
|
|
18
|
+
//# sourceMappingURL=local-auth.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-auth.guard.js","sourceRoot":"","sources":["../src/local-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA6C;AAGtC,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,IAAA,oBAAS,EAAC,OAAO,CAAC;CAAG,CAAA;AAA5C,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;GACA,cAAc,CAA8B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Strategy } from "passport-local";
|
|
2
|
+
declare const LocalStrategy_base: new (...args: [options: import("passport-local").IStrategyOptionsWithRequest] | [options: import("passport-local").IStrategyOptions] | []) => Strategy & {
|
|
3
|
+
validate(...args: any[]): unknown;
|
|
4
|
+
};
|
|
5
|
+
export declare class LocalStrategy extends LocalStrategy_base {
|
|
6
|
+
constructor();
|
|
7
|
+
validate(validateUser: Function): Promise<any>;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
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.LocalStrategy = void 0;
|
|
13
|
+
const passport_local_1 = require("passport-local");
|
|
14
|
+
const passport_1 = require("@nestjs/passport");
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
let LocalStrategy = class LocalStrategy extends (0, passport_1.PassportStrategy)(passport_local_1.Strategy) {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
async validate(validateUser) {
|
|
21
|
+
const user = await validateUser();
|
|
22
|
+
if (!user) {
|
|
23
|
+
throw new common_1.UnauthorizedException();
|
|
24
|
+
}
|
|
25
|
+
return user;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.LocalStrategy = LocalStrategy;
|
|
29
|
+
exports.LocalStrategy = LocalStrategy = __decorate([
|
|
30
|
+
(0, common_1.Injectable)(),
|
|
31
|
+
__metadata("design:paramtypes", [])
|
|
32
|
+
], LocalStrategy);
|
|
33
|
+
//# sourceMappingURL=local.srategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.srategy.js","sourceRoot":"","sources":["../src/local.srategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA0C;AAC1C,+CAAoD;AACpD,2CAAmE;AAG5D,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,IAAA,2BAAgB,EAAC,yBAAQ,CAAC;IACzD;QACI,KAAK,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,YAAsB;QACjC,MAAM,IAAI,GAAG,MAAM,YAAY,EAAE,CAAC;QAClC,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,MAAM,IAAI,8BAAqB,EAAE,CAAC;QACtC,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;AAZY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;;GACA,aAAa,CAYzB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Strategy } from "passport-local";
|
|
2
|
+
import { NestAuthInterface } from "./nestauth.interface";
|
|
3
|
+
declare const LocalStrategy_base: new (...args: [options: import("passport-local").IStrategyOptionsWithRequest] | [options: import("passport-local").IStrategyOptions] | []) => Strategy & {
|
|
4
|
+
validate(...args: any[]): unknown;
|
|
5
|
+
};
|
|
6
|
+
export declare class LocalStrategy extends LocalStrategy_base {
|
|
7
|
+
private readonly userService;
|
|
8
|
+
constructor(userService: NestAuthInterface);
|
|
9
|
+
validate(username: string, password: string, mobile: string): Promise<any>;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
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.LocalStrategy = void 0;
|
|
16
|
+
const passport_local_1 = require("passport-local");
|
|
17
|
+
const passport_1 = require("@nestjs/passport");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
let LocalStrategy = class LocalStrategy extends (0, passport_1.PassportStrategy)(passport_local_1.Strategy) {
|
|
20
|
+
constructor(userService) {
|
|
21
|
+
super();
|
|
22
|
+
this.userService = userService;
|
|
23
|
+
}
|
|
24
|
+
async validate(username, password, mobile) {
|
|
25
|
+
const user = await this.userService.validateUser({
|
|
26
|
+
username,
|
|
27
|
+
password,
|
|
28
|
+
mobile,
|
|
29
|
+
});
|
|
30
|
+
if (!user) {
|
|
31
|
+
throw new common_1.UnauthorizedException();
|
|
32
|
+
}
|
|
33
|
+
return user;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.LocalStrategy = LocalStrategy;
|
|
37
|
+
exports.LocalStrategy = LocalStrategy = __decorate([
|
|
38
|
+
(0, common_1.Injectable)(),
|
|
39
|
+
__param(0, (0, common_1.Inject)("UserService")),
|
|
40
|
+
__metadata("design:paramtypes", [Object])
|
|
41
|
+
], LocalStrategy);
|
|
42
|
+
//# sourceMappingURL=local.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.strategy.js","sourceRoot":"","sources":["../src/local.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mDAA0C;AAC1C,+CAAoD;AACpD,2CAA2E;AAIpE,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,IAAA,2BAAgB,EAAC,yBAAQ,CAAC;IACzD,YAC4C,WAA8B;QAEtE,KAAK,EAAE,CAAC;QAFgC,gBAAW,GAAX,WAAW,CAAmB;IAG1E,CAAC;IAED,KAAK,CAAC,QAAQ,CACV,QAAgB,EAChB,QAAgB,EAChB,MAAc;QAEd,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC;YAC7C,QAAQ;YACR,QAAQ;YACR,MAAM;SACT,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,MAAM,IAAI,8BAAqB,EAAE,CAAC;QACtC,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;AAtBY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAGJ,WAAA,IAAA,eAAM,EAAC,aAAa,CAAC,CAAA;;GAFjB,aAAa,CAsBzB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.NestauthController = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let NestauthController = class NestauthController {
|
|
12
|
+
};
|
|
13
|
+
exports.NestauthController = NestauthController;
|
|
14
|
+
exports.NestauthController = NestauthController = __decorate([
|
|
15
|
+
(0, common_1.Controller)('nestauth')
|
|
16
|
+
], NestauthController);
|
|
17
|
+
//# sourceMappingURL=nestauth.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nestauth.controller.js","sourceRoot":"","sources":["../../src/nestauth/nestauth.controller.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAGrC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;CAAG,CAAA;AAArB,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,EAAC,UAAU,CAAC;GACV,kBAAkB,CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|