From 74ad49adfb3c4c03adf41931f449665c651b035d Mon Sep 17 00:00:00 2001 From: Hyunmin Choi Date: Wed, 13 Nov 2024 22:01:29 +0900 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20API=20authToken=20=EA=B2=80=EC=A6=9D=20(#33)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 재학생 인증 API 의 authToken 저장 (#32) * feat: authToken 으로 회원가입 API 사용 (#32) --- src/api/accountApi.ts | 11 +++++++++-- src/components/account/RegisterForm.tsx | 2 +- src/hooks/useCustomAccount.ts | 6 +++--- src/types/Auth.ts | 1 + 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/api/accountApi.ts b/src/api/accountApi.ts index 61f31d2..ce7755d 100644 --- a/src/api/accountApi.ts +++ b/src/api/accountApi.ts @@ -20,5 +20,12 @@ export const login = async (loginParam: TLoginParam): Promise => export const auth = async (loginParam: TLoginParam): Promise => await api.post('/api/v1/auth', loginParam) -export const register = async (registerParam: TRegisterParam): Promise => - await api.post('/api/v1/accounts/register', registerParam) +export const register = async ( + registerParam: TRegisterParam, + authToken?: string +): Promise => + await api.post('/api/v1/accounts/register', registerParam, { + headers: { + Authorization: `Bearer ${authToken}` + } + }) diff --git a/src/components/account/RegisterForm.tsx b/src/components/account/RegisterForm.tsx index 47c32bc..68f49d0 100644 --- a/src/components/account/RegisterForm.tsx +++ b/src/components/account/RegisterForm.tsx @@ -38,7 +38,7 @@ const RegisterForm = () => { const handleClickRegister = () => { registerParams.password1 && registerParams.password2 ? registerParams.password1 === registerParams.password2 - ? doRegister(requestParam()).then(success => { + ? doRegister(requestParam(), authState.authToken).then(success => { success && moveToPath('/mypage') }) : alert('비밀번호가 일치하지 않습니다.') diff --git a/src/hooks/useCustomAccount.ts b/src/hooks/useCustomAccount.ts index 26e50a0..f2d5088 100644 --- a/src/hooks/useCustomAccount.ts +++ b/src/hooks/useCustomAccount.ts @@ -7,7 +7,7 @@ import {removeCookie, setCookie} from '../util/cookieUtil' export interface TCustomAccount { loginState: Member doLogin: (loginParam: TLoginParam) => Promise - doRegister: (registerParam: TRegisterParam) => Promise + doRegister: (registerParam: TRegisterParam, authToken?: string) => Promise doLogout: () => void saveAsCookie: (data: Member) => void isLogin: () => boolean @@ -27,8 +27,8 @@ const useCustomAccount = (): TCustomAccount => { } //----------회원가입 함수 - const doRegister = async (registerParam: TRegisterParam) => { - const response = await register(registerParam) + const doRegister = async (registerParam: TRegisterParam, authToken?: string) => { + const response = await register(registerParam, authToken) const success = response.status < 400 if (success) { removeCookie('auth') diff --git a/src/types/Auth.ts b/src/types/Auth.ts index 54f6c62..345ed90 100644 --- a/src/types/Auth.ts +++ b/src/types/Auth.ts @@ -3,4 +3,5 @@ export interface Auth { name?: string department?: string email?: string + authToken?: string }