-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[로그인뷰] 소셜로그인 post 연결
- Loading branch information
Showing
10 changed files
with
107 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import axios, { AxiosInstance } from "axios"; | ||
import axios, { AxiosInstance } from 'axios'; | ||
|
||
export const api: AxiosInstance = axios.create({ | ||
baseURL: import.meta.env.VITE_APP_BASE_URL, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useCallback, useState } from "react"; | ||
import kakao from "../../apis/kakao"; | ||
import { AxiosError } from "axios"; | ||
import { KakaoLoginInfoType, KakaoLoginResponseType } from "../../types/kakao"; | ||
|
||
const usePostKakao = () => { | ||
const [kakaoResponse, setKakaoResponse] = useState<KakaoLoginInfoType | null>(null); | ||
const [kakaoError, setKakaoError] = useState<AxiosError | null>(null); | ||
const [kakaoLoading, setKakaoLoading] = useState(false); | ||
|
||
const postKakao = useCallback(async (accessToken: string) => { | ||
if (!accessToken) return; | ||
setKakaoLoading(true); | ||
setKakaoError(null); | ||
try { | ||
const res = await kakao.postKakaoLogin({ kakaoToken: accessToken, fcmToken: "0" }); | ||
const data: KakaoLoginResponseType = res.data.data; | ||
setKakaoResponse({ | ||
userId: data.data.userId, | ||
accessToken: data.data.accessToken, | ||
isAlreadyUser: data.data.isAlreadyUser, | ||
refreshToken: data.data.refreshToken, | ||
nickname: data.data.nickname, | ||
}); | ||
console.log("응답이 왔나요?", kakaoResponse); | ||
localStorage.setItem("accessToken", data.data.accessToken); | ||
} catch (err) { | ||
setKakaoError(err as AxiosError); | ||
} finally { | ||
setKakaoLoading(false); | ||
} | ||
}, []); | ||
|
||
return { kakaoResponse, kakaoError, kakaoLoading, postKakao }; | ||
}; | ||
|
||
export default usePostKakao; |
2 changes: 1 addition & 1 deletion
2
src/hooks/queries/useKakaoLogin.tsx → src/hooks/useKakaoLogin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface CommonResponse { | ||
success: boolean; | ||
status: number; | ||
message: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters