Skip to content

Commit

Permalink
feat: 비밀번호 변경 페이지 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jane1107 committed May 3, 2024
1 parent 3abaa2c commit 59d45ef
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 56 deletions.
8 changes: 8 additions & 0 deletions src/apis/authApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ export const signIn = async ({ email, password }: SignInParams) => {

return data;
};

export const recoveryPasswd = async (email: string) => {
const { data, error } = await supabase.auth.resetPasswordForEmail(email);
if (error) {
throw error;
}
return data;
};
8 changes: 6 additions & 2 deletions src/components/EditPw/EditPwButton.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { useEditPwState } from '../../stores/editPwStore.ts';
import { recoveryPasswd } from '../../apis/authApis.ts';

const EditPwButton = () => {
const { email, name } = useEditPwState();
const { email } = useEditPwState();

const onClick = () => {
console.log('email: ', email);
console.log('name: ', name);
const result = recoveryPasswd(email);
result.then((value) => {
console.log(value);
});
};

return (
Expand Down
20 changes: 0 additions & 20 deletions src/components/EditPw/EmailInput.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions src/components/EditPw/NameInput.tsx

This file was deleted.

32 changes: 25 additions & 7 deletions src/pages/EditPwPage.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
import CenterPageLayout from '../layouts/CenterPageLayout.tsx';
import LoginForm from '../components/login/LoginForm.tsx';
import EmailInput from '../components/EditPw/EmailInput.tsx';
import NameInput from '../components/EditPw/NameInput.tsx';
import LoginFormActions from '../components/login/LoginFormActions.tsx';
import EditPwButton from '../components/EditPw/EditPwButton.tsx';
import InputForm from '../components/common/InputForm.tsx';
import { useEditPwState } from '../stores/editPwStore.ts';

const EditPwPage = () => {
const { email, emailHandler } = useEditPwState();

return (
<CenterPageLayout>
<LoginForm>
<NameInput />
<EmailInput />
</LoginForm>
<form className={'flex w-full flex-col'}>
<div className="card mb-10 w-96 bg-base-200 text-primary-content">
<div className="card-body">
<p>
새로운 비밀번호 등록이 가능한 링크를 <br />
이메일로 보내드립니다.
</p>
<p>회원가입 시 등록한 이메일 주소를 입력해주세요.</p>
</div>
</div>

<InputForm
defaultValue={email}
title={'이메일'}
placeholder={'이메일을 입력하세요'}
hint={''}
onChange={(e) => emailHandler(e.target.value)}
type={'email'}
name={'email'}
/>
</form>
<LoginFormActions>
<EditPwButton />
</LoginFormActions>
Expand Down
8 changes: 1 addition & 7 deletions src/stores/editPwStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ import { create } from 'zustand';

interface EditPwState {
email: string;
name: string;

emailHandler: (email: string) => void;
nameHandler: (name: string) => void;
}

export const useEditPwState = create<EditPwState>()((set) => ({
email: '',
name: '',

emailHandler: (email: string) => set((state) => ({ email, name: state.name })),
nameHandler: (name: string) => set((state) => ({ email: state.email, name })),
emailHandler: (email: string) => set(() => ({ email })),
}));

0 comments on commit 59d45ef

Please sign in to comment.