feat: refactoring auth & add email password login (#318)
* feat: wip * fix: issues * feat: clean controllers and services * fix: test * Fix auth --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
11
server/src/core/auth/dto/challenge.input.ts
Normal file
11
server/src/core/auth/dto/challenge.input.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class ChallengeInput {
|
||||
@IsNotEmpty()
|
||||
@IsEmail()
|
||||
email: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
5
server/src/core/auth/dto/login-token.entity.ts
Normal file
5
server/src/core/auth/dto/login-token.entity.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { TokenEntity } from './token.entity';
|
||||
|
||||
export class LoginTokenEntity {
|
||||
loginToken: TokenEntity;
|
||||
}
|
||||
7
server/src/core/auth/dto/refresh-token.input.ts
Normal file
7
server/src/core/auth/dto/refresh-token.input.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class RefreshTokenInput {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
refreshToken: string;
|
||||
}
|
||||
24
server/src/core/auth/dto/register.input.ts
Normal file
24
server/src/core/auth/dto/register.input.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import {
|
||||
IsEmail,
|
||||
IsNotEmpty,
|
||||
IsString,
|
||||
Matches,
|
||||
MinLength,
|
||||
} from 'class-validator';
|
||||
import { PASSWORD_REGEX } from '../auth.util';
|
||||
|
||||
export class RegisterInput {
|
||||
@IsNotEmpty()
|
||||
@IsEmail()
|
||||
email: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@MinLength(8)
|
||||
@Matches(PASSWORD_REGEX, { message: 'password too weak' })
|
||||
password: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
displayName: string;
|
||||
}
|
||||
4
server/src/core/auth/dto/token.entity.ts
Normal file
4
server/src/core/auth/dto/token.entity.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export class TokenEntity {
|
||||
token: string;
|
||||
expiresAt: Date;
|
||||
}
|
||||
11
server/src/core/auth/dto/verify.entity.ts
Normal file
11
server/src/core/auth/dto/verify.entity.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { TokenEntity } from './token.entity';
|
||||
import { User } from '@prisma/client';
|
||||
|
||||
export class VerifyEntity {
|
||||
user: Omit<User, 'passwordHash'>;
|
||||
|
||||
tokens: {
|
||||
accessToken: TokenEntity;
|
||||
refreshToken: TokenEntity;
|
||||
};
|
||||
}
|
||||
7
server/src/core/auth/dto/verify.input.ts
Normal file
7
server/src/core/auth/dto/verify.input.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class VerifyInput {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
loginToken: string;
|
||||
}
|
||||
Reference in New Issue
Block a user