add slug
This commit is contained in:
@@ -1,13 +1,18 @@
|
|||||||
import { IsNotEmpty, IsString, Matches } from 'class-validator';
|
import { IsNotEmpty, IsString, IsMobilePhone } from 'class-validator';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
export class RequestOtpDto {
|
export class RequestOtpDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsString()
|
@IsString()
|
||||||
@ApiProperty({ example: '09362532122', description: 'Mobile number' })
|
@ApiProperty({ example: '09362532122', description: 'Mobile number' })
|
||||||
@Matches(/^09\d{9}$/, {
|
// @Matches(/^09\d{9}$/, {
|
||||||
message: 'Mobile number must be a valid Iranian phone number (e.g., 09123456789)',
|
// message: 'Mobile number must be a valid Iranian phone number (e.g., 09123456789)',
|
||||||
})
|
// })
|
||||||
// @IsMobilePhone('fa-IR')
|
@IsMobilePhone('fa-IR')
|
||||||
phone: string;
|
phone: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ example: '', description: 'Restuarant slug' })
|
||||||
|
slug: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ export interface ILocalTokenPayload {
|
|||||||
|
|
||||||
export interface IConsoleTokenPayload {
|
export interface IConsoleTokenPayload {
|
||||||
id: string;
|
id: string;
|
||||||
permissions?: string[];
|
slug: string;
|
||||||
isAdmin?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITokenPayload extends ILocalTokenPayload, IConsoleTokenPayload {}
|
export interface ITokenPayload extends ILocalTokenPayload, IConsoleTokenPayload {}
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ export class AuthService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async requestOtp(dto: RequestOtpDto) {
|
async requestOtp(dto: RequestOtpDto) {
|
||||||
const { phone } = dto;
|
const { phone, slug } = dto;
|
||||||
const code = this.generateOtpCode();
|
const code = this.generateOtpCode();
|
||||||
|
|
||||||
await this.cacheService.set(`otp:${phone}`, code, 160);
|
await this.cacheService.set(`otp:${phone}:${slug}`, code, 160);
|
||||||
|
|
||||||
await this.smsService.sendOtp(phone, code);
|
await this.smsService.sendOtp(phone, code);
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export class TokensService {
|
|||||||
const refreshExpire = this.configService.getOrThrow<number>('REFRESH_TOKEN_EXPIRE');
|
const refreshExpire = this.configService.getOrThrow<number>('REFRESH_TOKEN_EXPIRE');
|
||||||
|
|
||||||
const accessToken = await this.jwtService.signAsync(payload, { expiresIn: `${accessExpire}m` });
|
const accessToken = await this.jwtService.signAsync(payload, { expiresIn: `${accessExpire}m` });
|
||||||
const refreshToken = await this.generateRefreshToken();
|
const refreshToken = this.generateRefreshToken();
|
||||||
|
|
||||||
await this.storeRefreshToken(payload.id, refreshToken, em);
|
await this.storeRefreshToken(payload.id, refreshToken, em);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Entity, ManyToOne, Opt, Property } from '@mikro-orm/core';
|
|||||||
|
|
||||||
import { User } from './user.entity';
|
import { User } from './user.entity';
|
||||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||||
|
|
||||||
@Entity({ tableName: 'refreshtokens' })
|
@Entity({ tableName: 'refreshtokens' })
|
||||||
export class RefreshToken extends BaseEntity {
|
export class RefreshToken extends BaseEntity {
|
||||||
@Property({ type: 'varchar', length: 255 })
|
@Property({ type: 'varchar', length: 255 })
|
||||||
|
|||||||
Reference in New Issue
Block a user