Skip to content

Commit

Permalink
[FEATURE] 회원가입 API authToken 검증 (#33)
Browse files Browse the repository at this point in the history
* feat: 재학생 인증 API 의 authToken 저장 (#32)

* feat: authToken 으로 회원가입 API 사용 (#32)
  • Loading branch information
hyunmin0317 authored Nov 13, 2024
1 parent cd5ab05 commit 74ad49a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/api/accountApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@ export const login = async (loginParam: TLoginParam): Promise<AxiosResponse> =>
export const auth = async (loginParam: TLoginParam): Promise<AxiosResponse> =>
await api.post('/api/v1/auth', loginParam)

export const register = async (registerParam: TRegisterParam): Promise<AxiosResponse> =>
await api.post('/api/v1/accounts/register', registerParam)
export const register = async (
registerParam: TRegisterParam,
authToken?: string
): Promise<AxiosResponse> =>
await api.post('/api/v1/accounts/register', registerParam, {
headers: {
Authorization: `Bearer ${authToken}`
}
})
2 changes: 1 addition & 1 deletion src/components/account/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('비밀번호가 일치하지 않습니다.')
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useCustomAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {removeCookie, setCookie} from '../util/cookieUtil'
export interface TCustomAccount {
loginState: Member
doLogin: (loginParam: TLoginParam) => Promise<boolean>
doRegister: (registerParam: TRegisterParam) => Promise<boolean>
doRegister: (registerParam: TRegisterParam, authToken?: string) => Promise<boolean>
doLogout: () => void
saveAsCookie: (data: Member) => void
isLogin: () => boolean
Expand All @@ -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')
Expand Down
1 change: 1 addition & 0 deletions src/types/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface Auth {
name?: string
department?: string
email?: string
authToken?: string
}

0 comments on commit 74ad49a

Please sign in to comment.