From 6365e75bc12dbc0a371135c4b0411bebf96d7438 Mon Sep 17 00:00:00 2001 From: Savien/Woo Jun Han <49388937+MrMirror21@users.noreply.github.com> Date: Tue, 22 Oct 2024 00:50:32 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20signup=20api=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=20=ED=95=A8=EC=88=98=20=EC=82=AC=EC=A0=84=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20#5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth.ts | 7 ++++++- src/hooks/api/useAuth.ts | 16 +++++++++++++++- src/types/api/auth.ts | 20 ++++++++++++++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/api/auth.ts b/src/api/auth.ts index b54f0c49..2b64f0a0 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -1,4 +1,4 @@ -import { SignInRequest, SignInResponse } from '@/types/api/auth'; +import { SignInRequest, SignInResponse, SignUpRequest, SignUpResponse } from '@/types/api/auth'; import { api } from './index.ts'; /** @@ -27,3 +27,8 @@ export const signIn = async ( const response = await api.post(`/auth/sign-in`, signinInfo); return response.data; }; + +export const signUp = async (signupInfo : SignUpRequest): Promise => { + const response = await api.post(`/auth/users`, signupInfo); + return response.data; +} \ No newline at end of file diff --git a/src/hooks/api/useAuth.ts b/src/hooks/api/useAuth.ts index a4fc5cd9..b98c7eeb 100644 --- a/src/hooks/api/useAuth.ts +++ b/src/hooks/api/useAuth.ts @@ -1,4 +1,4 @@ -import { signIn } from '@/api/auth'; +import { signIn, signUp } from '@/api/auth'; import { SignInResponse } from '@/types/api/auth'; import { setAccessToken } from '@/utils/auth'; import { useNavigate } from 'react-router-dom'; @@ -41,3 +41,17 @@ export const useSignIn = () => { }, }); }; + +export const useSignUp = () => { + const navigate = useNavigate(); + return useMutation({ + mutationFn: signUp, + onSuccess: (data: SignInResponse) => { + setAccessToken(data.access_token); + navigate('/information'); + }, + onError: () => { + navigate('/signin'); + }, + }); +}; \ No newline at end of file diff --git a/src/types/api/auth.ts b/src/types/api/auth.ts index b158f06a..f33ac5a7 100644 --- a/src/types/api/auth.ts +++ b/src/types/api/auth.ts @@ -1,9 +1,25 @@ +import { Address, Language, UserInfo } from './users'; + export type SignInRequest = { serial_id: string; password: string; -} +}; export type SignInResponse = { access_token: string; refresh_token: string; -} \ No newline at end of file +}; + +export type SignUpRequest = { + temporary_token: string; + user_info: UserInfo; + address: Address; + marketing_allowed: boolean; + notification_allowed: boolean; + language: Language; +}; + +export type SignUpResponse = { + access_token: string; + refresh_token: string; +};