MCPcopy Create free account
hub / github.com/GDGAlgiers/nest-init-cli / AuthFileManager

Class AuthFileManager

src/authStrategyMethods/authFileManager.ts:9–1277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import { FileManagerService } from '../utils/fileManager.service';
8import { promises as fs } from 'fs';
9export class AuthFileManager {
10 constructor(private readonly fileManagerService: FileManagerService) {}
11
12 async createFile(name: string, content: string, path: string): Promise<void> {
13 const authFolderPath = join(process.cwd(), 'src', path);
14
15 let moduleContent = content;
16 let filename = name;
17
18 try {
19 const filePath = join(authFolderPath, filename);
20 await writeFile(filePath, moduleContent);
21 console.log(`${filename} created successfully `);
22 } catch (err) {
23 console.error(`Failed to create ${filename} in auth folder:`, err);
24 throw err; // Rethrow the error to handle it further if needed
25 }
26 }
27
28 async createServices(): Promise<void> {
29 let filename = ``;
30 let authServiceContent = `
31/* eslint-disable prettier/prettier */
32import { Injectable } from '@nestjs/common';
33import { UsersService } from '../users/users.service';
34import * as bcrypt from 'bcryptjs';
35import { MailerService } from '@nestjs-modules/mailer';
36import { CreateUserDto } from '../users/dto/create-user.dto';
37
38@Injectable()
39export class AuthService {
40 constructor(
41 private usersService: UsersService,
42 private readonly mailerService: MailerService,
43 ) {}
44
45 async validateUserById(
46 id: number,
47 pass: string,
48 ): Promise<Omit<CreateUserDto, 'password'> | null> {
49 const user = await this.usersService.findOne(id);
50 if (
51 user &&
52 typeof user !== 'string' &&
53 (await bcrypt.compare(pass, user.password))
54 ) {
55 const { password, ...result } = user;
56 return result;
57 }
58 return null;
59 }
60
61 async validateUserByEmail(
62 email: string,
63 pass: string,
64 ): Promise<Omit<CreateUserDto, 'password'> | null> {
65 const user = await this.usersService.findByEmail(email);
66 if (

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected