-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/#67: 로그인 폼 이메일 기억하기 추가 #186
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b0f6303
feat: 이메일 로컬 저장소에 저장하기
SwimmingRiver 6182ea2
feat: 저장된 이메일 불러오기
SwimmingRiver e9301c3
feat: 테스트 코드 추가
SwimmingRiver 81fbf0c
feat: useEffect 대체 defaultValues 설정
SwimmingRiver 3f4c013
refactor: remeberEmail 폼 내부에서 isRememberEmail 로 변수명 변경
SwimmingRiver 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
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 |
|---|---|---|
| @@ -1,35 +1,58 @@ | ||
| import { SigninRequest } from '@/api/auth/type'; | ||
| import { SubmitHandler, useForm } from 'react-hook-form'; | ||
| import { SigninFormData } from '@/api/auth/type'; | ||
| import { SubmitHandler, useForm, UseFormProps } from 'react-hook-form'; | ||
| import { usePostSignin } from './usePostSignin'; | ||
|
|
||
| export const useSignInForm = () => { | ||
| export function useSignInForm(options: UseFormProps<SigninFormData>) { | ||
| const { mutate: signIn } = usePostSignin(); | ||
|
|
||
| const { | ||
| register, | ||
| handleSubmit, | ||
| setError, | ||
| setValue, | ||
| formState: { isSubmitting, errors }, | ||
| } = useForm<SigninRequest>(); | ||
| } = useForm<SigninFormData>({ | ||
| mode: 'onChange', | ||
| ...options, | ||
| }); | ||
|
|
||
| const onSubmit: SubmitHandler<SigninRequest> = (data) => { | ||
| signIn(data, { | ||
| onError: (error: Error) => { | ||
| const errorData = JSON.parse(error.message); | ||
| if ( | ||
| errorData.code === 'VALIDATION_ERROR' || | ||
| errorData.code === 'USER_NOT_FOUND' | ||
| ) { | ||
| setError('email', { type: 'manual', message: errorData.message }); | ||
| } | ||
| if (errorData.code === 'INVALID_CREDENTIALS') { | ||
| setError('password', { type: 'manual', message: errorData.message }); | ||
| } | ||
| }, | ||
| }); | ||
| const onSubmit: SubmitHandler<SigninFormData> = (data) => { | ||
| if (data.isRememberEmail) { | ||
| localStorage.setItem('rememberEmail', data.email); | ||
| } else { | ||
| localStorage.removeItem('rememberEmail'); | ||
| } | ||
|
|
||
| signIn( | ||
| { email: data.email, password: data.password }, | ||
| { | ||
| onError: (error: Error) => { | ||
| const errorData = JSON.parse(error.message); | ||
| if ( | ||
| errorData.code === 'VALIDATION_ERROR' || | ||
| errorData.code === 'USER_NOT_FOUND' | ||
| ) { | ||
| setError('email', { type: 'manual', message: errorData.message }); | ||
| } | ||
| if (errorData.code === 'INVALID_CREDENTIALS') { | ||
| setError('password', { | ||
| type: 'manual', | ||
| message: errorData.message, | ||
| }); | ||
| } | ||
| }, | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| return { onSubmit, register, handleSubmit, isSubmitting, errors }; | ||
| }; | ||
| return { | ||
| onSubmit, | ||
| register, | ||
| handleSubmit, | ||
| isSubmitting, | ||
| errors, | ||
| setValue, | ||
| }; | ||
| } | ||
|
|
||
| export default useSignInForm; | ||
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.
react hook form의
setError은 사용해본적이 없는데setError하면register내부에 유효성 검사에 걸린 것과 마찬가지로폼 에러 메시지가 출력되나요? (
errorData.message가 어떤식으로 출력되는지 텍스트나 스크린샷 첨부해주시면 감사할 것 같습니다!)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.
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.
오호 그렇군요 스크린샷 감사합니다! 지금은 서버에서 반환되는 메시지가 한글인데 나중에 Supabase 인증으로 변경되면
영어로 된 메시지가 출력될까요? 서버에서 한글 메시지를 반환하도록 변경하거나, 반환하는 메시지를 우리가 커스텀할 수 있는 지 확인해보면 좋을 것 같네요!