authentication module done

This commit is contained in:
VirajBrainvire
2024-02-26 11:23:44 +05:30
parent 4ffd94ec78
commit 0764793874
75 changed files with 2111 additions and 89 deletions

View File

@ -0,0 +1,38 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import * as nodemailer from 'nodemailer';
@Injectable()
export class EmailService {
private user: string;
private pass: string;
constructor(private readonly configService: ConfigService) {
this.user = this.configService.get<string>('email-config.EMAIL_ID');
this.pass = this.configService.get<string>('email-config.PASSWORD');
}
async sendOTPEmail(
email: string,
subject: string,
message: string,
): Promise<void> {
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: this.user,
pass: this.pass,
},
});
const mailOptions = {
from: this.user,
to: email,
subject,
text: message,
};
await transporter.sendMail(mailOptions);
}
}

View File

@ -0,0 +1,46 @@
export type Constructor<T, Arguments extends unknown[] = undefined[]> = new (
...arguments_: Arguments
) => T;
export type Plain<T> = T;
export type Optional<T> = T | undefined;
export type Nullable<T> = T | null;
export type PathImpl<T, Key extends keyof T> = Key extends string
? T[Key] extends Record<string, any>
?
| `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> &
string}`
| `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}`
: never
: never;
export type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
export type Path<T> = keyof T extends string
? PathImpl2<T> extends string | keyof T
? PathImpl2<T>
: keyof T
: never;
export type PathValue<
T,
P extends Path<T>
> = P extends `${infer Key}.${infer Rest}`
? Key extends keyof T
? Rest extends Path<T[Key]>
? PathValue<T[Key], Rest>
: never
: never
: P extends keyof T
? T[P]
: never;
export type KeyOfType<Entity, U> = {
[P in keyof Required<Entity>]: Required<Entity>[P] extends U
? P
: Required<Entity>[P] extends U[]
? P
: never;
}[keyof Entity];

View File

@ -0,0 +1,21 @@
import type { INestApplication } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
export function setupSwaggerAuthentication(app: INestApplication): void {
const options = new DocumentBuilder()
.setTitle('Authentication-Service')
.addBearerAuth({
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
in: 'header',
})
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api/authentication/documentation', app, document, {
swaggerOptions: {
persistAuthorization: true,
},
});
}