-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import axios from "axios"; | ||
|
||
export async function requestSocialLogin(provider, accessToken) { | ||
// 소셜 로그인 요청 | ||
export async function requestSocialLogin(platform, code) { | ||
const response = await axios.post("/api/auth/social-login", { | ||
provider: provider, | ||
access_token: accessToken, | ||
provider: platform, | ||
access_token: code, | ||
}); | ||
return response.data; | ||
} | ||
|
||
// 사용자 정보 조회 | ||
export async function fetchUserInfo(token) { | ||
const response = await axios.get(`/api/users/me`, { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
return response.data; | ||
} |
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,23 +1,25 @@ | ||
import React, { createContext, useContext, useState } from "react"; | ||
|
||
// AuthContext 생성 | ||
const AuthContext = createContext(); | ||
|
||
// Context Provider Component 생성 | ||
export function AuthProvider({ children }) { | ||
const [isLoggedIn, setLoggedIn] = useState(false); | ||
const [userInfo, setUserInfo] = useState(null); | ||
const [loggedIn, setLoggedIn] = useState(false); | ||
const [userInfo, setUserInfo] = useState(null); // 사용자 정보 전역 관리 | ||
|
||
return ( | ||
<AuthContext.Provider | ||
value={{ isLoggedIn, setLoggedIn, userInfo, setUserInfo }} | ||
value={{ | ||
loggedIn, | ||
setLoggedIn, | ||
userInfo, | ||
setUserInfo, | ||
}} | ||
> | ||
{children} | ||
</AuthContext.Provider> | ||
); | ||
} | ||
|
||
// Context 커스텀 훅 생성 | ||
export function useAuth() { | ||
return useContext(AuthContext); | ||
} |
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