feat: rewrite auth (#364)

* feat: wip rewrite auth

* feat: restructure folders and fix stories and tests

* feat: remove auth provider and fix tests
This commit is contained in:
Jérémy M
2023-06-23 17:49:50 +02:00
committed by GitHub
parent 1c7980b270
commit c6708b2c1f
54 changed files with 1268 additions and 584 deletions

View File

@ -1,10 +1,14 @@
import { ArgsType, Field } from '@nestjs/graphql';
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
@ArgsType()
export class ChallengeInput {
@Field(() => String)
@IsNotEmpty()
@IsEmail()
email: string;
@Field(() => String)
@IsNotEmpty()
@IsString()
password: string;

View File

@ -1,5 +1,8 @@
import { TokenEntity } from './token.entity';
import { Field, ObjectType } from '@nestjs/graphql';
import { AuthToken } from './token.entity';
export class LoginTokenEntity {
loginToken: TokenEntity;
@ObjectType()
export class LoginToken {
@Field(() => AuthToken)
loginToken: AuthToken;
}

View File

@ -1,6 +1,9 @@
import { ArgsType, Field } from '@nestjs/graphql';
import { IsNotEmpty, IsString } from 'class-validator';
@ArgsType()
export class RefreshTokenInput {
@Field(() => String)
@IsNotEmpty()
@IsString()
refreshToken: string;

View File

@ -6,18 +6,23 @@ import {
MinLength,
} from 'class-validator';
import { PASSWORD_REGEX } from '../auth.util';
import { ArgsType, Field } from '@nestjs/graphql';
@ArgsType()
export class RegisterInput {
@Field(() => String)
@IsNotEmpty()
@IsEmail()
email: string;
@Field(() => String)
@IsNotEmpty()
@IsString()
@MinLength(8)
@Matches(PASSWORD_REGEX, { message: 'password too weak' })
password: string;
@Field(() => String)
@IsNotEmpty()
@IsString()
displayName: string;

View File

@ -1,4 +1,25 @@
export class TokenEntity {
import { Field, ObjectType } from '@nestjs/graphql';
@ObjectType()
export class AuthToken {
@Field(() => String)
token: string;
@Field(() => Date)
expiresAt: Date;
}
@ObjectType()
export class AuthTokenPair {
@Field(() => AuthToken)
accessToken: AuthToken;
@Field(() => AuthToken)
refreshToken: AuthToken;
}
@ObjectType()
export class AuthTokens {
@Field(() => AuthTokenPair)
tokens: AuthTokenPair;
}

View File

@ -1,11 +1,9 @@
import { TokenEntity } from './token.entity';
import { User } from '@prisma/client';
import { Field, ObjectType } from '@nestjs/graphql';
import { AuthTokens } from './token.entity';
import { User } from 'src/core/@generated/user/user.model';
export class VerifyEntity {
user: Omit<User, 'passwordHash'>;
tokens: {
accessToken: TokenEntity;
refreshToken: TokenEntity;
};
@ObjectType()
export class Verify extends AuthTokens {
@Field(() => User)
user: User;
}

View File

@ -1,6 +1,9 @@
import { ArgsType, Field } from '@nestjs/graphql';
import { IsNotEmpty, IsString } from 'class-validator';
@ArgsType()
export class VerifyInput {
@Field(() => String)
@IsNotEmpty()
@IsString()
loginToken: string;