Skip to content

Commit

Permalink
✨ feat: signup api 연결 함수 사전 작성 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMirror21 committed Oct 21, 2024
1 parent ac4b5bd commit 6365e75
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/api/auth.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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<SignUpResponse> => {
const response = await api.post(`/auth/users`, signupInfo);
return response.data;
}
16 changes: 15 additions & 1 deletion src/hooks/api/useAuth.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
},
});
};
20 changes: 18 additions & 2 deletions src/types/api/auth.ts
Original file line number Diff line number Diff line change
@@ -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;
}
};

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;
};

0 comments on commit 6365e75

Please sign in to comment.