mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
refactor: remove login by password and biometric
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
import { Body, Controller, Headers, HttpCode, HttpStatus, Post, Req, UseGuards } from '@nestjs/common';
|
import { Body, Controller, HttpCode, HttpStatus, Post, Req, UseGuards } from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
import { DEVICE_ID_HEADER } from '~/common/constants';
|
|
||||||
import { AuthenticatedUser, Public } from '~/common/decorators';
|
import { AuthenticatedUser, Public } from '~/common/decorators';
|
||||||
import { AccessTokenGuard } from '~/common/guards';
|
import { AccessTokenGuard } from '~/common/guards';
|
||||||
import { ApiDataResponse, ApiLangRequestHeader } from '~/core/decorators';
|
import { ApiDataResponse, ApiLangRequestHeader } from '~/core/decorators';
|
||||||
@ -131,8 +130,8 @@ export class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('login')
|
@Post('login')
|
||||||
async login(@Body() loginDto: LoginRequestDto, @Headers(DEVICE_ID_HEADER) deviceId: string) {
|
async login(@Body() loginDto: LoginRequestDto) {
|
||||||
const [res, user] = await this.authService.login(loginDto, deviceId);
|
const [res, user] = await this.authService.login(loginDto);
|
||||||
return ResponseFactory.data(new LoginResponseDto(res, user));
|
return ResponseFactory.data(new LoginResponseDto(res, user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { IsEmail, IsEnum, IsNotEmpty, IsOptional, IsString, ValidateIf } from 'c
|
|||||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||||
import { GrantType } from '~/auth/enums';
|
import { GrantType } from '~/auth/enums';
|
||||||
export class LoginRequestDto {
|
export class LoginRequestDto {
|
||||||
@ApiProperty({ example: GrantType.PASSWORD })
|
@ApiProperty({ example: GrantType.APPLE })
|
||||||
@IsEnum(GrantType, { message: i18n('validation.IsEnum', { path: 'general', property: 'auth.grantType' }) })
|
@IsEnum(GrantType, { message: i18n('validation.IsEnum', { path: 'general', property: 'auth.grantType' }) })
|
||||||
grantType!: GrantType;
|
grantType!: GrantType;
|
||||||
|
|
||||||
|
|||||||
@ -260,10 +260,14 @@ export class AuthService {
|
|||||||
this.logger.log(`Passcode updated successfully for user with email ${email}`);
|
this.logger.log(`Passcode updated successfully for user with email ${email}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(loginDto: LoginRequestDto, deviceId: string): Promise<[ILoginResponse, User]> {
|
async login(loginDto: LoginRequestDto): Promise<[ILoginResponse, User]> {
|
||||||
let user: User;
|
let user: User;
|
||||||
let tokens: ILoginResponse;
|
let tokens: ILoginResponse;
|
||||||
|
|
||||||
|
if (loginDto.grantType === GrantType.PASSWORD || loginDto.grantType === GrantType.BIOMETRIC) {
|
||||||
|
throw new BadRequestException('AUTH.GRANT_TYPE_NOT_SUPPORTED_YET');
|
||||||
|
}
|
||||||
|
|
||||||
if (loginDto.grantType === GrantType.GOOGLE) {
|
if (loginDto.grantType === GrantType.GOOGLE) {
|
||||||
this.logger.log(`Logging in user with email ${loginDto.email} using google`);
|
this.logger.log(`Logging in user with email ${loginDto.email} using google`);
|
||||||
[tokens, user] = await this.loginWithGoogle(loginDto);
|
[tokens, user] = await this.loginWithGoogle(loginDto);
|
||||||
@ -274,22 +278,6 @@ export class AuthService {
|
|||||||
[tokens, user] = await this.loginWithApple(loginDto);
|
[tokens, user] = await this.loginWithApple(loginDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loginDto.grantType === GrantType.PASSWORD) {
|
|
||||||
this.logger.log(`Logging in user with email ${loginDto.email} using password`);
|
|
||||||
[tokens, user] = await this.loginWithPassword(loginDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loginDto.grantType === GrantType.BIOMETRIC) {
|
|
||||||
this.logger.log(`Logging in user with email ${loginDto.email} using biometric`);
|
|
||||||
[tokens, user] = await this.loginWithBiometric(loginDto, deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.deviceService.updateDevice(deviceId, {
|
|
||||||
lastAccessOn: new Date(),
|
|
||||||
fcmToken: loginDto.fcmToken,
|
|
||||||
userId: user!.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.log(`User with email ${loginDto.email} logged in successfully`);
|
this.logger.log(`User with email ${loginDto.email} logged in successfully`);
|
||||||
|
|
||||||
return [tokens!, user!];
|
return [tokens!, user!];
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
"otp": "رمز التحقق",
|
"otp": "رمز التحقق",
|
||||||
"grantType": "نوع الإذن",
|
"grantType": "نوع الإذن",
|
||||||
"signature": "التوقيع",
|
"signature": "التوقيع",
|
||||||
|
"appleToken": "رمز أبل",
|
||||||
"googleToken": "رمز جوجل",
|
"googleToken": "رمز جوجل",
|
||||||
"fcmToken": "رمز FCM",
|
"fcmToken": "رمز FCM",
|
||||||
"refreshToken": "رمز التحديث",
|
"refreshToken": "رمز التحديث",
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
"otp": "OTP",
|
"otp": "OTP",
|
||||||
"grantType": "Grant type",
|
"grantType": "Grant type",
|
||||||
"signature": "Signature",
|
"signature": "Signature",
|
||||||
|
"appleToken": "Apple token",
|
||||||
"googleToken": "Google token",
|
"googleToken": "Google token",
|
||||||
"fcmToken": "FCM token",
|
"fcmToken": "FCM token",
|
||||||
"refreshToken": "Refresh token",
|
"refreshToken": "Refresh token",
|
||||||
|
|||||||
Reference in New Issue
Block a user