-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 회원가입 입력 폼 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dfce9a0
feat(auth): implement signup form with validation and api integration
kkhhmm3103 70be73c
chore(deps): pin axios version to 1.13.6
kkhhmm3103 43a5406
refactor(auth): apply axios, zod, react-query to signup flow
kkhhmm3103 28ac69a
chore(deps): update pnpm-lock.yaml for axios pin
gaeunnlee 87d2d6e
fix(test): wrap AppHeader test with QueryClientProvider
gaeunnlee 2f6053c
refactor(auth): simplify error handling using ApiError
kkhhmm3103 b851720
refactor(auth): unify oauth request and error handling
kkhhmm3103 b0b6221
fix(auth): handle blocked popup in oauth login flow
kkhhmm3103 ea2f6de
fix(auth): correct signup api path and align response schema
kkhhmm3103 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { z } from 'zod' | ||
|
|
||
| import { baseApi } from '@/shared/api/base-api' | ||
|
|
||
| /** | ||
| * Zod schema (응답 검증) | ||
| */ | ||
| export const signupResponseSchema = z.object({ | ||
| status: z.number(), | ||
| code: z.string(), | ||
| message: z.string(), | ||
| data: z.object({ | ||
| userId: z.string(), | ||
| email: z.string(), | ||
| nickname: z.string() | ||
| }) | ||
| }) | ||
|
|
||
| export type SignupResponse = z.infer<typeof signupResponseSchema> | ||
|
|
||
| /** | ||
| * 요청 타입 | ||
| */ | ||
| type SignupRequest = { | ||
| email: string | ||
| nickname: string | ||
| password: string | ||
| } | ||
|
|
||
| /** | ||
| * API 함수 | ||
| */ | ||
| export async function signup(request: SignupRequest) { | ||
| const response = await baseApi.post('/api/auth/signup', request) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. baseApi의 baseURL에 이미 /api가 포함되어 있어서 실제 요청이 /api/api/auth/signup으로 나갑니다! /auth/signup으로 변경하면 될 것 같아요!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. baseURL과 중복되지 않도록 /auth/signup로 수정했습니다!! 감사합니다~ |
||
| // 응답 검증 | ||
| return signupResponseSchema.parse(response.data) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| export type SignupFormData = { | ||
| nickname: string | ||
| email: string | ||
| password: string | ||
| confirmPassword: string | ||
| inviteCode: string | ||
| } | ||
|
|
||
| export type SignupFieldName = keyof SignupFormData | ||
| export type SignupFieldErrors = Partial<Record<SignupFieldName, string>> | ||
|
|
||
| export interface SignupResponseData { | ||
| userId: string | ||
| email: string | ||
| nickname: string | ||
| } | ||
|
|
||
| export interface ApiResponse<T> { | ||
| status: number | ||
| code: string | ||
| message: string | ||
| data: T | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| export const initialSignupFormData: SignupFormData = { | ||
| nickname: '', | ||
| email: '', | ||
| password: '', | ||
| confirmPassword: '', | ||
| inviteCode: '' | ||
| } | ||
|
|
||
| export const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ | ||
|
|
||
| export function validateSignupField( | ||
| field: SignupFieldName, | ||
| value: string, | ||
| currentFormData: SignupFormData | ||
| ) { | ||
| switch (field) { | ||
| case 'nickname': | ||
| if (!value.trim()) return '닉네임을 입력해주세요.' | ||
| if (value.trim().length < 2) return '닉네임은 2자 이상 입력해주세요.' | ||
| if (value.trim().length > 20) return '닉네임은 20자 이하로 입력해주세요.' | ||
| return '' | ||
|
|
||
| case 'email': | ||
| if (!value.trim()) return '이메일을 입력해주세요.' | ||
| if (!emailRegex.test(value.trim())) return '올바른 이메일 형식을 입력해주세요.' | ||
| return '' | ||
|
|
||
| case 'password': | ||
| if (!value) return '비밀번호를 입력해주세요.' | ||
| if (value.length < 8) return '비밀번호는 8자 이상 입력해주세요.' | ||
| return '' | ||
|
|
||
| case 'confirmPassword': | ||
| if (!value) return '비밀번호 확인을 입력해주세요.' | ||
| if (value !== currentFormData.password) return '비밀번호가 일치하지 않습니다.' | ||
| return '' | ||
|
|
||
| case 'inviteCode': | ||
| return '' | ||
|
|
||
| default: | ||
| return '' | ||
| } | ||
| } | ||
|
|
||
| export function validateSignupForm(currentFormData: SignupFormData, isEmailVerified: boolean) { | ||
| const nextErrors: SignupFieldErrors = {} | ||
|
|
||
| ;(Object.keys(currentFormData) as SignupFieldName[]).forEach((field) => { | ||
| const message = validateSignupField(field, currentFormData[field], currentFormData) | ||
| if (message) { | ||
| nextErrors[field] = message | ||
| } | ||
| }) | ||
|
|
||
| if (!isEmailVerified) { | ||
| nextErrors.email = nextErrors.email || '이메일 인증이 필요합니다.' | ||
| } | ||
|
|
||
| return nextErrors | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 signupResponseSchema가 백엔드 공통 응답 포맷과 맞지 않아 정상 응답이 반환되더라도 Zod 검증 단계에서 실패하면서 화면에서는 에러로 표시됩니다!
이미 공통 응답을 처리하는 apiResponseSchema 헬퍼가 있으니 개별 API에서 응답 구조를 다시 정의하기보다 해당 헬퍼를 재사용하는 방식으로 통일하면 좋을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apiResponse를 사용하도록 수정했습니다!