-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[전수빈] week15 #545
The head ref may contain hidden characters: "part3-\uC804\uC218\uBE48-week15"
[전수빈] week15 #545
Changes from 1 commit
6ff9e42
a4ba74c
7bef125
b1a62a7
52a54db
643f5a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ApiMapper } from "@/lib/apiMapper"; | ||
import request from "@/lib/axios"; | ||
|
||
interface UserData { | ||
email: string; | ||
password: string; | ||
} | ||
|
||
interface SaveTokenProps { | ||
accessToken: string; | ||
refreshToken: string; | ||
} | ||
|
||
export const signin = async (data: UserData) => { | ||
try { | ||
const response = await request.post(`${ApiMapper.auth.post.SIGN_IN}`, data); | ||
|
||
if (response.status === 200) { | ||
const { data } = response; | ||
saveToken(data.data); | ||
return true; | ||
} | ||
throw new Error(); | ||
} catch (e) { | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 멘토링 시간때 에러핸들링 관련해서 말씀드렸던것처럼 이 함수에서는 차라리 error를 catch하지 않는 것이 좋습니다. |
||
} | ||
}; | ||
|
||
export const signup = async (data: UserData) => { | ||
try { | ||
const response = await request.post(`${ApiMapper.auth.post.SIGN_UP}`, data); | ||
|
||
if (response.status === 200) { | ||
const { data } = response; | ||
saveToken(data.data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인증 관련 파일 내부에서 token관리를 하고 계시네요 관심사에 맞게 잘 하고 계십니다. 👍 |
||
return true; | ||
} | ||
throw new Error(); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
|
||
const saveToken = ({ accessToken, refreshToken }: SaveTokenProps) => { | ||
localStorage.setItem("accessToken", accessToken); | ||
localStorage.setItem("refreshToken", refreshToken); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { useRouter } from "next/router"; | |
import { useEffect } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { userData } from "./signin"; | ||
import { signup } from "@/lib/api/auth.ts/auth"; | ||
|
||
interface SignupData extends userData { | ||
passwordConfirm: string; | ||
|
@@ -92,11 +93,9 @@ const Signup = () => { | |
} | ||
|
||
try { | ||
const result = await request.post(`${ApiMapper.auth.post.SIGN_UP}`, data); | ||
const result = await signup(data); | ||
|
||
if (result.status === 200) { | ||
const { data } = result; | ||
localStorage.setItem("accessToken", data.data.accessToken); | ||
if (result) { | ||
router.push("/folder"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. localStorage관련 코드가 사라져서 훨씬 깔끔하네요. signUp(data, {redirectTo: '/folder'}); |
||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Props라는 이름은
properties
를 축약한 것으로 react에서 html properties스펙에 맞게 지은 이름입니다.이 타입은 html props가 아니니까 굳이 props라는 이름을 지을 필요가 없습니다. 차라리
PersistedTokens
같은 이름이 좋을 것 같아요