@open-kingdom/shared-backend-feature-authentication 0.0.2-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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # feature-backend-auth
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build feature-backend-auth` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test feature-backend-auth` to execute the unit tests via [Jest](https://jestjs.io).
@@ -0,0 +1,2 @@
1
+ export * from './lib/feature-backend-auth.module';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/feature-backend-auth.module"), exports);
@@ -0,0 +1,19 @@
1
+ import { AuthenticationService } from './authentication.service';
2
+ import type { RequestWithUser } from './auth.types';
3
+ export declare class AuthController {
4
+ private authenticationService;
5
+ constructor(authenticationService: AuthenticationService);
6
+ login(req: RequestWithUser): Promise<{
7
+ access_token: string;
8
+ }>;
9
+ getProfile(req: RequestWithUser): Omit<{
10
+ id: number;
11
+ firstName: string | null;
12
+ lastName: string | null;
13
+ email: string;
14
+ invitee: number | null;
15
+ role: "guest" | "user" | "admin" | null;
16
+ password: string;
17
+ }, "password">;
18
+ }
19
+ //# sourceMappingURL=auth.controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../src/lib/auth.controller.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,qBAEa,cAAc;IAEb,OAAO,CAAC,qBAAqB;gBAArB,qBAAqB,EAAE,qBAAqB;IAsC1D,KAAK,CAAY,GAAG,EAAE,eAAe;;;IA4B3C,UAAU,CAAY,GAAG,EAAE,eAAe;;;;;;;;;CAG3C"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthController = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const swagger_1 = require("@nestjs/swagger");
7
+ const passport_1 = require("@nestjs/passport");
8
+ const authentication_service_1 = require("./authentication.service");
9
+ const auth_dto_1 = require("./auth.dto");
10
+ let AuthController = class AuthController {
11
+ /* c8 ignore next */
12
+ constructor(authenticationService) {
13
+ this.authenticationService = authenticationService;
14
+ }
15
+ /* c8 ignore next */
16
+ async login(req) {
17
+ return this.authenticationService.login(req.user);
18
+ }
19
+ /* c8 ignore next */
20
+ getProfile(req) {
21
+ return req.user;
22
+ }
23
+ };
24
+ exports.AuthController = AuthController;
25
+ tslib_1.__decorate([
26
+ (0, swagger_1.ApiOperation)({
27
+ summary: 'User login',
28
+ description: 'Authenticate user with email and password credentials',
29
+ }),
30
+ (0, swagger_1.ApiBody)({
31
+ type: auth_dto_1.LoginDto,
32
+ description: 'User login credentials',
33
+ examples: {
34
+ admin: {
35
+ summary: 'Admin login',
36
+ value: {
37
+ email: 'admin@admin.com',
38
+ password: 'admin',
39
+ },
40
+ },
41
+ },
42
+ }),
43
+ (0, swagger_1.ApiResponse)({
44
+ status: 200,
45
+ description: 'Login successful',
46
+ type: auth_dto_1.LoginResponseDto,
47
+ }),
48
+ (0, swagger_1.ApiUnauthorizedResponse)({
49
+ description: 'Invalid credentials - email or password is incorrect',
50
+ schema: {
51
+ type: 'object',
52
+ properties: {
53
+ statusCode: { type: 'number', example: 401 },
54
+ message: { type: 'string', example: 'Invalid credentials' },
55
+ error: { type: 'string', example: 'Unauthorized' },
56
+ },
57
+ },
58
+ }),
59
+ (0, common_1.UseGuards)((0, passport_1.AuthGuard)('local')),
60
+ (0, common_1.Post)('auth/login')
61
+ /* c8 ignore next */
62
+ ,
63
+ tslib_1.__param(0, (0, common_1.Request)()),
64
+ tslib_1.__metadata("design:type", Function),
65
+ tslib_1.__metadata("design:paramtypes", [Object]),
66
+ tslib_1.__metadata("design:returntype", Promise)
67
+ ], AuthController.prototype, "login", null);
68
+ tslib_1.__decorate([
69
+ (0, swagger_1.ApiBearerAuth)('JWT-auth'),
70
+ (0, common_1.UseGuards)((0, passport_1.AuthGuard)('jwt')),
71
+ (0, common_1.Get)('profile'),
72
+ (0, swagger_1.ApiOperation)({
73
+ summary: 'Get user profile',
74
+ description: 'Returns the authenticated user profile. Requires a valid JWT token in the Authorization header.',
75
+ }),
76
+ (0, swagger_1.ApiResponse)({
77
+ status: 200,
78
+ description: 'User profile retrieved successfully',
79
+ type: auth_dto_1.ProfileResponseDto,
80
+ }),
81
+ (0, swagger_1.ApiUnauthorizedResponse)({
82
+ description: 'Unauthorized - Invalid or missing JWT token',
83
+ schema: {
84
+ type: 'object',
85
+ properties: {
86
+ statusCode: { type: 'number', example: 401 },
87
+ message: { type: 'string', example: 'Unauthorized' },
88
+ },
89
+ },
90
+ })
91
+ /* c8 ignore next */
92
+ ,
93
+ tslib_1.__param(0, (0, common_1.Request)()),
94
+ tslib_1.__metadata("design:type", Function),
95
+ tslib_1.__metadata("design:paramtypes", [Object]),
96
+ tslib_1.__metadata("design:returntype", void 0)
97
+ ], AuthController.prototype, "getProfile", null);
98
+ exports.AuthController = AuthController = tslib_1.__decorate([
99
+ (0, swagger_1.ApiTags)('Authentication'),
100
+ (0, common_1.Controller)(),
101
+ tslib_1.__metadata("design:paramtypes", [authentication_service_1.AuthenticationService])
102
+ ], AuthController);
@@ -0,0 +1,16 @@
1
+ export declare class LoginDto {
2
+ email: string;
3
+ password: string;
4
+ }
5
+ export declare class LoginResponseDto {
6
+ access_token: string;
7
+ }
8
+ export declare class ProfileResponseDto {
9
+ id: number;
10
+ firstName: string | null;
11
+ lastName: string | null;
12
+ email: string;
13
+ invitee: number | null;
14
+ role: 'guest' | 'user' | 'admin';
15
+ }
16
+ //# sourceMappingURL=auth.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.dto.d.ts","sourceRoot":"","sources":["../../src/lib/auth.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAQ;IAMnB,KAAK,SAAM;IAOX,QAAQ,SAAM;CACf;AAED,qBAAa,gBAAgB;IAK3B,YAAY,EAAG,MAAM,CAAC;CACvB;AAED,qBAAa,kBAAkB;IAK7B,EAAE,EAAG,MAAM,CAAC;IAOZ,SAAS,EAAG,MAAM,GAAG,IAAI,CAAC;IAO1B,QAAQ,EAAG,MAAM,GAAG,IAAI,CAAC;IAMzB,KAAK,EAAG,MAAM,CAAC;IAOf,OAAO,EAAG,MAAM,GAAG,IAAI,CAAC;IAOxB,IAAI,EAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;CACnC"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProfileResponseDto = exports.LoginResponseDto = exports.LoginDto = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const swagger_1 = require("@nestjs/swagger");
6
+ class LoginDto {
7
+ constructor() {
8
+ this.email = '';
9
+ this.password = '';
10
+ }
11
+ }
12
+ exports.LoginDto = LoginDto;
13
+ tslib_1.__decorate([
14
+ (0, swagger_1.ApiProperty)({
15
+ description: 'User email address',
16
+ example: 'admin@admin.com',
17
+ format: 'email',
18
+ }),
19
+ tslib_1.__metadata("design:type", Object)
20
+ ], LoginDto.prototype, "email", void 0);
21
+ tslib_1.__decorate([
22
+ (0, swagger_1.ApiProperty)({
23
+ description: 'User password',
24
+ example: 'admin',
25
+ minLength: 1,
26
+ }),
27
+ tslib_1.__metadata("design:type", Object)
28
+ ], LoginDto.prototype, "password", void 0);
29
+ class LoginResponseDto {
30
+ }
31
+ exports.LoginResponseDto = LoginResponseDto;
32
+ tslib_1.__decorate([
33
+ (0, swagger_1.ApiProperty)({
34
+ description: 'JWT access token',
35
+ example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
36
+ }),
37
+ tslib_1.__metadata("design:type", String)
38
+ ], LoginResponseDto.prototype, "access_token", void 0);
39
+ class ProfileResponseDto {
40
+ }
41
+ exports.ProfileResponseDto = ProfileResponseDto;
42
+ tslib_1.__decorate([
43
+ (0, swagger_1.ApiProperty)({
44
+ description: 'User ID',
45
+ example: 1,
46
+ }),
47
+ tslib_1.__metadata("design:type", Number)
48
+ ], ProfileResponseDto.prototype, "id", void 0);
49
+ tslib_1.__decorate([
50
+ (0, swagger_1.ApiProperty)({
51
+ description: 'User first name',
52
+ example: 'John',
53
+ nullable: true,
54
+ }),
55
+ tslib_1.__metadata("design:type", Object)
56
+ ], ProfileResponseDto.prototype, "firstName", void 0);
57
+ tslib_1.__decorate([
58
+ (0, swagger_1.ApiProperty)({
59
+ description: 'User last name',
60
+ example: 'Doe',
61
+ nullable: true,
62
+ }),
63
+ tslib_1.__metadata("design:type", Object)
64
+ ], ProfileResponseDto.prototype, "lastName", void 0);
65
+ tslib_1.__decorate([
66
+ (0, swagger_1.ApiProperty)({
67
+ description: 'User email address',
68
+ example: 'john@example.com',
69
+ }),
70
+ tslib_1.__metadata("design:type", String)
71
+ ], ProfileResponseDto.prototype, "email", void 0);
72
+ tslib_1.__decorate([
73
+ (0, swagger_1.ApiProperty)({
74
+ description: 'ID of user who invited this user',
75
+ example: null,
76
+ nullable: true,
77
+ }),
78
+ tslib_1.__metadata("design:type", Object)
79
+ ], ProfileResponseDto.prototype, "invitee", void 0);
80
+ tslib_1.__decorate([
81
+ (0, swagger_1.ApiProperty)({
82
+ description: 'User role',
83
+ example: 'user',
84
+ enum: ['guest', 'user', 'admin'],
85
+ }),
86
+ tslib_1.__metadata("design:type", String)
87
+ ], ProfileResponseDto.prototype, "role", void 0);
@@ -0,0 +1,7 @@
1
+ import { User } from '@open-kingdom/shared-backend-data-access-users';
2
+ import { Request } from 'express';
3
+ export interface RequestWithUser extends Request {
4
+ user: Omit<User, 'password'>;
5
+ logout: () => void;
6
+ }
7
+ //# sourceMappingURL=auth.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.types.d.ts","sourceRoot":"","sources":["../../src/lib/auth.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gDAAgD,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,WAAW,eAAgB,SAAQ,OAAO;IAC9C,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC7B,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { JwtService } from '@nestjs/jwt';
2
+ import { User, UsersService } from '@open-kingdom/shared-backend-data-access-users';
3
+ export declare class AuthenticationService {
4
+ private usersService;
5
+ private jwtService;
6
+ constructor(usersService: UsersService, jwtService: JwtService);
7
+ validateUser(email: string, password: string): Promise<Omit<User, 'password'>>;
8
+ login(user: Omit<User, 'password'>): Promise<{
9
+ access_token: string;
10
+ }>;
11
+ }
12
+ //# sourceMappingURL=authentication.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.service.d.ts","sourceRoot":"","sources":["../../src/lib/authentication.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EACL,IAAI,EACJ,YAAY,EACb,MAAM,gDAAgD,CAAC;AAExD,qBACa,qBAAqB;IAE9B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,UAAU;gBADV,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU;IAG1B,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAc5B,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;CAM7E"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthenticationService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const jwt_1 = require("@nestjs/jwt");
7
+ const bcrypt = tslib_1.__importStar(require("bcrypt"));
8
+ const shared_backend_data_access_users_1 = require("@open-kingdom/shared-backend-data-access-users");
9
+ let AuthenticationService = class AuthenticationService {
10
+ constructor(usersService, jwtService) {
11
+ this.usersService = usersService;
12
+ this.jwtService = jwtService;
13
+ }
14
+ async validateUser(email, password) {
15
+ const user = await this.usersService.findOne(email);
16
+ if (!user) {
17
+ throw new common_1.UnauthorizedException('Invalid credentials');
18
+ }
19
+ const isValid = await bcrypt.compare(password, user.password);
20
+ if (!isValid) {
21
+ throw new common_1.UnauthorizedException('Invalid credentials');
22
+ }
23
+ const { password: _, ...result } = user;
24
+ return result;
25
+ }
26
+ async login(user) {
27
+ const payload = { username: user.email, id: user.id };
28
+ return {
29
+ access_token: this.jwtService.sign(payload),
30
+ };
31
+ }
32
+ };
33
+ exports.AuthenticationService = AuthenticationService;
34
+ exports.AuthenticationService = AuthenticationService = tslib_1.__decorate([
35
+ (0, common_1.Injectable)(),
36
+ tslib_1.__metadata("design:paramtypes", [shared_backend_data_access_users_1.UsersService,
37
+ jwt_1.JwtService])
38
+ ], AuthenticationService);
@@ -0,0 +1,9 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ export interface AuthModuleOptions {
3
+ jwtSecret: string;
4
+ jwtExpiresIn?: string;
5
+ }
6
+ export declare class OpenKingdomFeatureBackendAuthModule {
7
+ static forRoot(options: AuthModuleOptions): DynamicModule;
8
+ }
9
+ //# sourceMappingURL=feature-backend-auth.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-backend-auth.module.d.ts","sourceRoot":"","sources":["../../src/lib/feature-backend-auth.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAWvD,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBACa,mCAAmC;IAC9C,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa;CAwB1D"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var OpenKingdomFeatureBackendAuthModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.OpenKingdomFeatureBackendAuthModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const jwt_1 = require("@nestjs/jwt");
8
+ const passport_1 = require("@nestjs/passport");
9
+ const shared_backend_data_access_users_1 = require("@open-kingdom/shared-backend-data-access-users");
10
+ const authentication_service_1 = require("./authentication.service");
11
+ const passport_local_strategy_1 = require("./passport-local-strategy");
12
+ const auth_controller_1 = require("./auth.controller");
13
+ const passport_jwt_strategy_1 = require("./passport-jwt-strategy");
14
+ let OpenKingdomFeatureBackendAuthModule = OpenKingdomFeatureBackendAuthModule_1 = class OpenKingdomFeatureBackendAuthModule {
15
+ static forRoot(options) {
16
+ return {
17
+ module: OpenKingdomFeatureBackendAuthModule_1,
18
+ imports: [
19
+ shared_backend_data_access_users_1.OpenKingdomDataAccessBackendUsersModule,
20
+ passport_1.PassportModule,
21
+ jwt_1.JwtModule.register({
22
+ secret: options.jwtSecret,
23
+ signOptions: { expiresIn: options.jwtExpiresIn || '60s' },
24
+ }),
25
+ ],
26
+ controllers: [auth_controller_1.AuthController],
27
+ providers: [
28
+ authentication_service_1.AuthenticationService,
29
+ passport_local_strategy_1.LocalStrategy,
30
+ passport_jwt_strategy_1.JwtStrategy,
31
+ {
32
+ provide: passport_jwt_strategy_1.JWT_CONSTANTS,
33
+ useValue: { secret: options.jwtSecret },
34
+ },
35
+ ],
36
+ exports: [authentication_service_1.AuthenticationService, passport_jwt_strategy_1.JwtStrategy],
37
+ };
38
+ }
39
+ };
40
+ exports.OpenKingdomFeatureBackendAuthModule = OpenKingdomFeatureBackendAuthModule;
41
+ exports.OpenKingdomFeatureBackendAuthModule = OpenKingdomFeatureBackendAuthModule = OpenKingdomFeatureBackendAuthModule_1 = tslib_1.__decorate([
42
+ (0, common_1.Module)({})
43
+ ], OpenKingdomFeatureBackendAuthModule);
@@ -0,0 +1,25 @@
1
+ import { Strategy } from 'passport-jwt';
2
+ import { UsersService } from '@open-kingdom/shared-backend-data-access-users';
3
+ export declare const JWT_CONSTANTS = "JWT_CONSTANTS";
4
+ declare const JwtStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
5
+ validate(...args: any[]): unknown;
6
+ };
7
+ export declare class JwtStrategy extends JwtStrategy_base {
8
+ private usersService;
9
+ constructor(usersService: UsersService, jwtConstants: {
10
+ secret: string;
11
+ });
12
+ validate(payload: {
13
+ username: string;
14
+ id: number;
15
+ }): Promise<{
16
+ id: number;
17
+ firstName: string | null;
18
+ lastName: string | null;
19
+ email: string;
20
+ invitee: number | null;
21
+ role: "guest" | "user" | "admin" | null;
22
+ }>;
23
+ }
24
+ export {};
25
+ //# sourceMappingURL=passport-jwt-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passport-jwt-strategy.d.ts","sourceRoot":"","sources":["../../src/lib/passport-jwt-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIpD,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAE9E,eAAO,MAAM,aAAa,kBAAkB,CAAC;;;;AAE7C,qBACa,WAAY,SAAQ,gBAA0B;IAEvD,OAAO,CAAC,YAAY;gBAAZ,YAAY,EAAE,YAAY,EACX,YAAY,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE;IASnD,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE;;;;;;;;CASzD"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JwtStrategy = exports.JWT_CONSTANTS = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const passport_jwt_1 = require("passport-jwt");
6
+ const passport_1 = require("@nestjs/passport");
7
+ const common_1 = require("@nestjs/common");
8
+ const shared_backend_data_access_users_1 = require("@open-kingdom/shared-backend-data-access-users");
9
+ exports.JWT_CONSTANTS = 'JWT_CONSTANTS';
10
+ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
11
+ constructor(usersService, jwtConstants) {
12
+ super({
13
+ jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
14
+ ignoreExpiration: false,
15
+ secretOrKey: jwtConstants.secret,
16
+ });
17
+ this.usersService = usersService;
18
+ }
19
+ async validate(payload) {
20
+ const user = await this.usersService.findOne(payload.username);
21
+ if (!user) {
22
+ throw new common_1.UnauthorizedException();
23
+ }
24
+ // Exclude password from the returned user object
25
+ const { password: _, ...userWithoutPassword } = user;
26
+ return userWithoutPassword;
27
+ }
28
+ };
29
+ exports.JwtStrategy = JwtStrategy;
30
+ exports.JwtStrategy = JwtStrategy = tslib_1.__decorate([
31
+ (0, common_1.Injectable)(),
32
+ tslib_1.__param(1, (0, common_1.Inject)(exports.JWT_CONSTANTS)),
33
+ tslib_1.__metadata("design:paramtypes", [shared_backend_data_access_users_1.UsersService, Object])
34
+ ], JwtStrategy);
@@ -0,0 +1,13 @@
1
+ import { Strategy } from 'passport-local';
2
+ import { User } from '@open-kingdom/shared-backend-data-access-users';
3
+ import { AuthenticationService } from './authentication.service';
4
+ declare const LocalStrategy_base: new (...args: [options: import("passport-local").IStrategyOptionsWithRequest] | [options: import("passport-local").IStrategyOptions] | []) => Strategy & {
5
+ validate(...args: any[]): unknown;
6
+ };
7
+ export declare class LocalStrategy extends LocalStrategy_base {
8
+ private authenticationService;
9
+ constructor(authenticationService: AuthenticationService);
10
+ validate(username: string, password: string): Promise<Omit<User, 'password'>>;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=passport-local-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passport-local-strategy.d.ts","sourceRoot":"","sources":["../../src/lib/passport-local-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI1C,OAAO,EAAE,IAAI,EAAE,MAAM,gDAAgD,CAAC;AAEtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;;;;AAEjE,qBACa,aAAc,SAAQ,kBAA0B;IAC/C,OAAO,CAAC,qBAAqB;gBAArB,qBAAqB,EAAE,qBAAqB;IAM1D,QAAQ,CACZ,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;CAUnC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalStrategy = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const passport_local_1 = require("passport-local");
6
+ const passport_1 = require("@nestjs/passport");
7
+ const common_1 = require("@nestjs/common");
8
+ const authentication_service_1 = require("./authentication.service");
9
+ let LocalStrategy = class LocalStrategy extends (0, passport_1.PassportStrategy)(passport_local_1.Strategy) {
10
+ constructor(authenticationService) {
11
+ super({
12
+ usernameField: 'email', // Tell passport to use 'email' field as username
13
+ });
14
+ this.authenticationService = authenticationService;
15
+ }
16
+ async validate(username, password) {
17
+ const user = await this.authenticationService.validateUser(username, password);
18
+ if (!user) {
19
+ throw new common_1.UnauthorizedException();
20
+ }
21
+ return user;
22
+ }
23
+ };
24
+ exports.LocalStrategy = LocalStrategy;
25
+ exports.LocalStrategy = LocalStrategy = tslib_1.__decorate([
26
+ (0, common_1.Injectable)(),
27
+ tslib_1.__metadata("design:paramtypes", [authentication_service_1.AuthenticationService])
28
+ ], LocalStrategy);
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@open-kingdom/shared-backend-feature-authentication",
3
+ "version": "0.0.2-0",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ "./package.json": "./package.json",
9
+ ".": {
10
+ "development": "./src/index.ts",
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "!**/*.tsbuildinfo"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "dependencies": {
24
+ "@nestjs/common": "11.1.6",
25
+ "tslib": "2.8.1",
26
+ "@nestjs/passport": "11.0.5",
27
+ "@nestjs/jwt": "11.0.0",
28
+ "bcrypt": "^5.1.1",
29
+ "passport-jwt": "^4.0.1",
30
+ "passport-local": "^1.0.0",
31
+ "@nestjs/swagger": "^11.0.0",
32
+ "@open-kingdom/shared-backend-data-access-users": "0.0.2-0",
33
+ "express": "5.1.0"
34
+ },
35
+ "nx": {
36
+ "name": "@open-kingdom/shared-backend-feature-authentication",
37
+ "tags": [
38
+ "type:feature",
39
+ "scope:shared",
40
+ "environment:backend"
41
+ ]
42
+ }
43
+ }