Skip to content

Commit

Permalink
Merge pull request #54 from MatheusSanchez/google-auth-test
Browse files Browse the repository at this point in the history
Change user creation useCase to accept authentication with Google
  • Loading branch information
MatheusSanchez authored Feb 4, 2024
2 parents eaf494f + d72bb07 commit 2ad15a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/controller/user/registerUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export async function registerUser(
) {
const registerBodySchema = z.object({
name: z.string(),
surname: z.string(),
surname: z.string().optional(),
email: z.string().email(),
password: z.string().min(6),
avatar_url: z.string().optional(),
is_google: z.boolean().optional()
})

const { name, surname, email, password } = registerBodySchema.parse(
const { name, surname, email, password, avatar_url, is_google } = registerBodySchema.parse(
request.body,
)

Expand All @@ -27,6 +29,8 @@ export async function registerUser(
surname,
email,
password,
avatar_url,
is_google,
})
} catch (error) {
if (error instanceof UserAlreadyExistsError) {
Expand Down
10 changes: 8 additions & 2 deletions src/use-cases/user/createUserUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { User } from '@prisma/client'

interface CreateUserUseCaseRequest {
name: string
surname: string
surname?: string
email: string
password: string
avatar_url?: string
is_google?: boolean
}

interface CreateUserUseCaseResponse {
Expand All @@ -22,6 +24,8 @@ export class CreateUserUseCase {
surname,
email,
password,
avatar_url,
is_google
}: CreateUserUseCaseRequest): Promise<CreateUserUseCaseResponse> {

const userWithSameEmail = await this.usersRepository.findByEmail(email)
Expand All @@ -35,7 +39,9 @@ export class CreateUserUseCase {
name,
surname,
email,
password_hash
password_hash,
avatar_url,
is_google
})

return {
Expand Down

0 comments on commit 2ad15a1

Please sign in to comment.