nestjs-auth-kit
Version:
A modular and flexible authentication kit for NestJS with JWT, social login, OTP, and password reset.
46 lines • 2.36 kB
JavaScript
;
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.ForgotPasswordService = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const typeorm_2 = require("typeorm");
const user_entity_1 = require("../entities/user.entity");
const otp_service_1 = require("./otp.service");
let ForgotPasswordService = class ForgotPasswordService {
constructor(userRepository, otpService) {
this.userRepository = userRepository;
this.otpService = otpService;
}
async resetPassword(email, otp, newPassword) {
const isValidOtp = await this.otpService.verifyOtp(email, otp);
if (!isValidOtp) {
throw new Error('Invalid or expired OTP.');
}
const user = await this.userRepository.findOne({ where: { email } });
if (!user) {
throw new Error('User not found.');
}
user.password = newPassword; // Hash the password before saving in a real app
await this.userRepository.save(user);
}
};
exports.ForgotPasswordService = ForgotPasswordService;
exports.ForgotPasswordService = ForgotPasswordService = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, typeorm_1.InjectRepository)(user_entity_1.User)),
__metadata("design:paramtypes", [typeorm_2.Repository,
otp_service_1.OtpService])
], ForgotPasswordService);
//# sourceMappingURL=forgot-password.service.js.map