-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update:: 비밀번호 재설정 훅 분리, apis 작성 #140
훅을 분리하여 이메일 인증과 비밀번호 변경 함수를 불러오도록 작성하고 apis를 작성해서 서버로 post를 보내서 이메일 인증,비밀 번호 변경한 내용을 post로 보내도록 작성했습니다.
- Loading branch information
1 parent
4d7f2ff
commit 3976f2e
Showing
3 changed files
with
87 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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,18 @@ | ||
import { IDAcustomAxios } from "@/util/CustomAxios/customAxios" | ||
|
||
export interface ChangePasswordRepository { | ||
changePassword(email: string, password: string): Promise<void> | ||
sendEmailAuth(email: string): Promise<void> | ||
} | ||
|
||
class ChangePasswordRepositoryImpl implements ChangePasswordRepository { | ||
public async changePassword(email: string, password: string): Promise<void> { | ||
await IDAcustomAxios.post("/api/change-password", { email, password }) | ||
} | ||
|
||
public async sendEmailAuth(email: string): Promise<void> { | ||
await IDAcustomAxios.post("/api/send-email-auth", { email }) | ||
} | ||
} | ||
|
||
export default new ChangePasswordRepositoryImpl() |
This file contains 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 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,48 @@ | ||
// src/api/useChangePasswordQuery.ts | ||
import { ChangePasswordRepository } from "@/apis/ChangePassword/ChangePasswordRepositoryImpl" | ||
import type { ChangePasswordFormData } from "@/components/ChangePassword/type" | ||
import { UseFormGetValues } from "react-hook-form" | ||
|
||
export const useChangePasswordQuery = () => { | ||
const onsubmit = async ( | ||
data: ChangePasswordFormData, | ||
isEmailAuth: boolean, | ||
repository: ChangePasswordRepository, | ||
): Promise<void> => { | ||
if (!isEmailAuth) { | ||
alert("이메일 인증을 완료해주세요.") | ||
} | ||
try { | ||
await repository.changePassword(data.email, data.password) | ||
|
||
alert("비밀번호가 성공적으로 변경되었습니다.") | ||
} catch (error) { | ||
console.error("비밀번호 변경 중 에러 발생:", error) | ||
alert("비밀번호 변경에 실패했습니다. 다시 시도해주세요.") | ||
} | ||
} | ||
|
||
const handleEmailAuth = async ( | ||
getValues: UseFormGetValues<ChangePasswordFormData>, | ||
setIsEmailAuth: (value: boolean) => void, | ||
repository: ChangePasswordRepository, | ||
): Promise<void> => { | ||
const email = getValues("email") | ||
if (!email) { | ||
alert("이메일을 입력해주세요.") | ||
} | ||
try { | ||
await repository.sendEmailAuth(email) | ||
setIsEmailAuth(true) | ||
alert("이메일 인증이 완료되었습니다.") | ||
} catch (error) { | ||
console.error("이메일 인증 중 에러 발생:", error) | ||
alert("이메일 인증에 실패했습니다. 다시 시도해주세요.") | ||
} | ||
} | ||
return { | ||
onsubmit, | ||
handleEmailAuth, | ||
} | ||
} | ||
export default useChangePasswordQuery |