-
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.
Merge pull request #147 from JNU-econovation/FE
Fe
- Loading branch information
Showing
17 changed files
with
491 additions
and
204 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,80 +1,6 @@ | ||
import axios from "axios"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
// Axios 기본 설정 | ||
axios.defaults.baseURL = import.meta.env.VITE_ERROR_API; | ||
axios.defaults.headers.common["Content-Type"] = "application/json"; | ||
axios.defaults.withCredentials = true; | ||
|
||
let isRefreshing = false; | ||
let refreshSubscribers = []; | ||
|
||
const onRefreshed = (token) => { | ||
refreshSubscribers.map((cb) => cb(token)); | ||
}; | ||
|
||
const addRefreshSubscriber = (cb) => { | ||
refreshSubscribers.push(cb); | ||
}; | ||
|
||
axios.interceptors.request.use( | ||
(config) => { | ||
const token = localStorage.getItem("slackToken"); | ||
if (token) { | ||
config.headers["Authorization"] = `Bearer ${token}`; | ||
} | ||
return config; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
axios.interceptors.response.use( | ||
(response) => { | ||
return response; | ||
}, | ||
async (error) => { | ||
const originalRequest = error.config; | ||
if (error.response.status === 401 && !originalRequest._retry) { | ||
if (isRefreshing) { | ||
return new Promise((resolve) => { | ||
addRefreshSubscriber((token) => { | ||
originalRequest.headers["Authorization"] = "Bearer " + token; | ||
resolve(axios(originalRequest)); | ||
}); | ||
}); | ||
} | ||
|
||
originalRequest._retry = true; | ||
isRefreshing = true; | ||
|
||
const refreshToken = localStorage.getItem("refreshToken"); | ||
|
||
return new Promise((resolve, reject) => { | ||
axios | ||
.post("/auth/reissue", { refreshToken: refreshToken }) | ||
.then(({ data }) => { | ||
const newToken = data.data.accessToken; | ||
localStorage.setItem("slackToken", newToken); | ||
axios.defaults.headers.common["Authorization"] = | ||
"Bearer " + newToken; | ||
originalRequest.headers["Authorization"] = "Bearer " + newToken; | ||
onRefreshed(newToken); | ||
resolve(axios(originalRequest)); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
useNavigate().push("/login"); | ||
}) | ||
.finally(() => { | ||
isRefreshing = false; | ||
refreshSubscribers = []; | ||
}); | ||
}); | ||
} | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
export default axios; |
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 |
---|---|---|
@@ -1,12 +1,66 @@ | ||
import styled from "styled-components"; | ||
import { useState } from "react"; | ||
import { HiPencil } from "react-icons/hi2"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
const ProfileBar = () => { | ||
return <StyledProfileFrame></StyledProfileFrame>; | ||
const [isHovered, setIsHovered] = useState(false); | ||
const navigate = useNavigate(); | ||
|
||
const handleProfileClick = () => { | ||
navigate("/profile"); | ||
}; | ||
|
||
return ( | ||
<StyledProfileFrame> | ||
<ProfileImageContainer | ||
onMouseEnter={() => setIsHovered(true)} | ||
onMouseLeave={() => setIsHovered(false)} | ||
onClick={handleProfileClick} | ||
> | ||
<ProfileImage src="seed0838.png" alt="Profile" /> | ||
{isHovered && ( | ||
<EditIconOverlay> | ||
<HiPencil /> | ||
</EditIconOverlay> | ||
)} | ||
</ProfileImageContainer> | ||
</StyledProfileFrame> | ||
); | ||
}; | ||
|
||
export default ProfileBar; | ||
|
||
const StyledProfileFrame = styled.div` | ||
width: 20rem; | ||
height: 18.4375rem; | ||
width: 15.625rem; | ||
height: 15rem; | ||
align-items: center; | ||
display: flex; | ||
flex-direction: column; | ||
margin-bottom: 0.6rem; | ||
`; | ||
|
||
const ProfileImageContainer = styled.div` | ||
position: relative; | ||
cursor: pointer; | ||
`; | ||
|
||
const ProfileImage = styled.img` | ||
margin-top: 1.25rem; | ||
width: 13rem; | ||
`; | ||
|
||
const EditIconOverlay = styled.div` | ||
position: absolute; | ||
top: 1rem; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
border-radius: 50%; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
color: white; | ||
font-size: 2rem; | ||
`; |
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
Oops, something went wrong.