Skip to content

Commit c8a1cfb

Browse files
committed
refactor: return name on login
1 parent 16d63aa commit c8a1cfb

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/infrastructure/clients/AuthenticationClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export const account1 = {
1717

1818
export const account2 = {
1919
name: 'Name Two',
20-
email: 'two@mail.com',
21-
password: 'user2'
20+
email: 'any_email5@mail.com',
21+
password: 'Secr&t123'
2222
}
2323

2424
export const authenticationClientAccountsStorage: AccountDto[] = [new Account(account1), new Account(account2)]
@@ -42,7 +42,7 @@ export class AuthenticationClient implements IAuthenticationClient {
4242
if (account && account.password === password) {
4343
const loginToken = crypto.randomUUID() //Generate fake token for login
4444
loginTokens.push(loginToken)
45-
return { loginToken, id: account.id }
45+
return { loginToken, id: account.id, name: account.name }
4646
}
4747
throw new BadRequestException(ClientErrorMessages.INVALID_CREDENTIALS)
4848
}

src/modules/authentication/application/AuthenticationService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export class AuthenticationService implements IAuthenticationService {
1919
this.validateZipCode(body.zipCode)
2020
const newAccount = await this.authenticationClient.createAccount(new Account(body))
2121

22-
if (newAccount) return newAccount
22+
if (newAccount) {
23+
console.log('Logger: Account Created for user: ' + newAccount.email)
24+
return newAccount
25+
}
2326

2427
throw new InternalServerErrorException(AuthenticationErrorMessages.SIGNUP_ERROR)
2528
}
@@ -30,7 +33,7 @@ export class AuthenticationService implements IAuthenticationService {
3033
if (!zipCode) {
3134
console.log('Logger: no zipCode to validate.')
3235
return
33-
}
36+
}
3437
if (zipCode === '99999999') {
3538
throw new BadRequestException(AuthenticationErrorMessages.INVALID_ZIPCODE)
3639
}

src/modules/authentication/presentation/dtos/LoginDto.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { IsEmail, IsNotEmpty, IsString, MaxLength, MinLength } from 'class-validator'
22

3-
43
export type LoginResultDto = {
5-
id: string
64
loginToken: string
5+
id: string
6+
name: string
77
}
88

99
export class LoginDto {
@@ -13,9 +13,9 @@ export class LoginDto {
1313
@MinLength(5)
1414
@MaxLength(255)
1515
email: string
16-
16+
1717
@IsString()
18-
@IsNotEmpty()
18+
@IsNotEmpty()
1919
@MinLength(4)
2020
@MaxLength(255)
2121
password: string

src/modules/users/presentation/users.http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GET http://localhost:3003/users
2-
Authorization: 50410911-af21-4435-a25a-2471c5f4b703
2+
Authorization: 66708c0d-5cea-4fde-a3df-23232acadb75
33
content-type: application/json
44

55
{}

0 commit comments

Comments
 (0)