mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 10:25:23 +00:00
authentication module done
This commit is contained in:
38
libs/common/src/util/email.service.ts
Normal file
38
libs/common/src/util/email.service.ts
Normal 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);
|
||||
}
|
||||
}
|
46
libs/common/src/util/types.ts
Normal file
46
libs/common/src/util/types.ts
Normal 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];
|
||||
|
21
libs/common/src/util/user-auth.swagger.utils.ts
Normal file
21
libs/common/src/util/user-auth.swagger.utils.ts
Normal 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,
|
||||
},
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user