UNPKG

nest-authify

Version:

Complete authentication and authorization package for NestJS - Monolith and Microservices ready with OAuth, JWT, Redis sessions

70 lines 3.19 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthService = void 0; const common_1 = require("@nestjs/common"); const jwt_1 = require("@nestjs/jwt"); const config_1 = require("@nestjs/config"); const base_auth_service_1 = require("./base-auth.service"); const hash_service_1 = require("./hash.service"); let AuthService = class AuthService extends base_auth_service_1.BaseAuthService { constructor(jwtService, sessionStore, hashService, repository, configService) { super(jwtService, sessionStore, hashService, repository, configService); } async getUserById(userId) { if (!this.repository) { throw new Error('Auth repository not configured'); } return this.repository.findUserById(userId); } async getUserActiveSessions(userId) { const sessions = []; return sessions; } hasRole(user, role) { return user.roles && user.roles.includes(role); } hasPermission(user, permission) { return user.permissions && user.permissions.includes(permission); } async updateUserProfile(userId, data) { if (!this.repository) { throw new Error('Auth repository not configured'); } const { password, ...updateData } = data; return this.repository.updateUser(userId, updateData); } async deactivateUser(userId) { if (!this.repository) { throw new Error('Auth repository not configured'); } await this.repository.updateUser(userId, { isActive: false }); await this.revokeAllUserSessions(userId); } async activateUser(userId) { if (!this.repository) { throw new Error('Auth repository not configured'); } await this.repository.updateUser(userId, { isActive: true }); } }; exports.AuthService = AuthService; exports.AuthService = AuthService = __decorate([ (0, common_1.Injectable)(), __param(3, (0, common_1.Optional)()), __param(3, (0, common_1.Inject)('AUTH_REPOSITORY')), __param(4, (0, common_1.Optional)()), __metadata("design:paramtypes", [jwt_1.JwtService, Object, hash_service_1.HashService, Object, config_1.ConfigService]) ], AuthService); //# sourceMappingURL=auth.service.js.map