Skip to content

Commit c6dda30

Browse files
authored
[EC-70] FE/feat: 리프레시 토큰 API 연동 (#58)
* [EC-70] chore: WIP * [EC-70] feat: accessToken 재발급 API 연동 * [EC-70] feat: 인증 예외 경로 추가 - /api/auth/refresh * [EC-70] chore: 주석 정리 * [EC-70] chore: 코드 정리
1 parent c06aed4 commit c6dda30

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

api/src/main/java/org/example/educheck/global/security/config/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
3535
.sessionManagement(session -> session
3636
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
3737
.authorizeHttpRequests(auth -> auth
38-
.requestMatchers("/api/auth/login", "/api/auth/signup").permitAll()
38+
.requestMatchers("/api/auth/login", "/api/auth/signup", "/api/auth/refresh").permitAll()
3939
.anyRequest().authenticated()
4040
// TODO: 인증 엔드포인트 수정
4141
)

client/src/App.jsx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1-
import React from "react";
2-
import { RouterProvider } from "react-router-dom";
3-
import router from "./router";
4-
5-
import { Provider } from 'react-redux';
6-
import store from './store/store';
1+
import React, { useEffect } from 'react';
2+
import { RouterProvider } from 'react-router-dom';
3+
import router from './router';
4+
import { authApi } from './api/authApi';
5+
import { login } from './store/slices/authSlice';
6+
import { useDispatch } from 'react-redux';
7+
import { setRole } from './store/slices/sideBarItemSlice';
78

89
export default function App() {
10+
const dispatch = useDispatch();
11+
12+
useEffect(() => {
13+
const fetchRefreshToken = async () => {
14+
try {
15+
const response = await authApi.reissue();
16+
const accessToken = response.headers?.authorization ?? '';
17+
dispatch(
18+
login({
19+
...response.data.data,
20+
accessToken: accessToken,
21+
}),
22+
setRole(response.data.data),
23+
);
24+
} catch (error) {
25+
console.error(error);
26+
}
27+
};
28+
29+
fetchRefreshToken();
30+
}, []);
31+
932
return (
1033
<>
11-
<Provider store={store}>
12-
<RouterProvider router={router}></RouterProvider>
13-
</Provider>
34+
<RouterProvider router={router}></RouterProvider>
1435
</>
1536
);
16-
}
37+
}

client/src/api/authApi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const authApi = {
1919

2020
reissue: async () => {
2121
const response = await apiInstance.post(
22-
'/auth/reissue',
22+
'/auth/refresh',
2323
{},
2424
{
2525
withCredentials: true,

client/src/main.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import { StrictMode } from 'react'
22
import { createRoot } from 'react-dom/client'
33
import App from './App.jsx';
44
import './css/index.css';
5+
import { Provider } from 'react-redux';
6+
import store from './store/store.js';
57

68
createRoot(document.getElementById('root')).render(
79
<StrictMode>
8-
<App />
10+
<Provider store={store}>
11+
<App />
12+
</Provider>
913
</StrictMode>,
10-
)
14+
);

client/src/pages/login/Login.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ export default function Login() {
1919
password: '',
2020
});
2121
const [isLoginButtonEnable, setIsLoginButtonEnable] = useState(false);
22+
23+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
2224

2325
const handleInputChange = (event) => {
26+
const { name, value } = event.target;
2427
setInputData((prev) => ({
2528
...prev,
26-
[event.target.name]: event.target.value,
29+
[name]: value,
2730
}));
2831
};
2932

0 commit comments

Comments
 (0)