Skip to content

Commit

Permalink
Feat: Signup API 흐름 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
soulchicken committed Oct 2, 2023
1 parent ca3200e commit 0d23b04
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/pages/signup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import DivideLineText from '@/components/common/divideLine/DivideLineText';
import Input from '@/components/common/input/Input';
import PasswordInput from '@/components/common/input/PasswordInput';
import Button from '@/components/common/button/Button';
import { credentialsSignupAPI } from '@/utils/api/accounts';
import { credentialNextSignupAPI } from '@/utils/api/accounts';

const Signup = () => {
const [username, setUsername] = useState('');
Expand All @@ -21,7 +21,7 @@ const Signup = () => {

const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
const signupData = await credentialsSignupAPI({
const signupData = await credentialNextSignupAPI({
email, username, password, confirmPassword,
});

Expand Down
37 changes: 28 additions & 9 deletions src/utils/api/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import defaultInstance from '@/utils/axiosInstance/defaultInstance';
import clientInstance from '../axiosInstance/clientInstance';

interface Credentials {
email: string, password: string, provider: string
}

interface NextSignupForm {
email: string,
username: string,
password: string,
confirmPassword: string,
}

interface SignupForm {
email: string, username: string, password: string, confirmPassword: string
email: string, name: string, password: string,
}

interface Socials {
Expand All @@ -17,16 +25,27 @@ export const credentialsLoginAPI = async (credentials : Credentials) => {
return result.data;
};

export const credentialsSignupAPI = async (signupForm : SignupForm) => {
if (signupForm.password !== signupForm.confirmPassword) {
// TODO: 비밀번호 일치 여부 확인 후 실패시 알려주는 UI가 필요함
return { error: '비밀번호를 다시 확인해주세요.' };
}
export const credentialNextSignupAPI = async ({
email, username, password, confirmPassword,
} : NextSignupForm) => {
const sendSignupData = {
email,
username,
password,
confirmPassword,
};

const result = await clientInstance.post('users/signup', JSON.stringify(sendSignupData));
return result.data;
};

export const credentialsSignupAPI = async ({
email, name, password,
} : SignupForm) => {
const sendSignupData = {
email: signupForm.email,
name: signupForm.username,
password: signupForm.password,
email,
name,
password,
provider: 'Credential',
};

Expand Down

0 comments on commit 0d23b04

Please sign in to comment.