Skip to content

Commit

Permalink
feat: 새로고침시 로그인 유지 (#66)
Browse files Browse the repository at this point in the history
로그인 시 유저 정보 세션 스토리지에 저장 후 로그인 체크
  • Loading branch information
Lavegaa committed Nov 28, 2020
1 parent 98a69b6 commit 7f316e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function App() {
<Switch>
<Route exact path="/" component={LoginPage} />
<AuthRoute path="/conference" component={ConferenceButton} />
<Route path="/questionlist" component={QuestionListPage} />
<AuthRoute path="/questionlist" component={QuestionListPage} />
<Route path="/question/:id" component={QuestionPage} />
<Route path="/room/:roomID" component={ConferenceRoom} />
<Route component={NotFound} />
Expand Down
13 changes: 11 additions & 2 deletions src/components/AuthRoute/AuthRoute.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Route, Redirect } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import PropTypes from 'prop-types';
import { get } from '../../utils/snippet';
import { setLogin } from '../../store/Auth/auth';

export default function AuthRoute({ component: Component, render, ...rest }) {
const dispatch = useDispatch();
const authSelector = useSelector(get('auth'));
useEffect(() => {
const name = sessionStorage.getItem('name');
const email = sessionStorage.getItem('email');
if (name !== authSelector.name) {
dispatch(setLogin({ email, name }));
}
}, []);
return (
<Route
{...rest}
Expand Down
2 changes: 2 additions & 0 deletions src/store/Auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const authReducer = createSlice({
},
reducers: {
setLogin(state, { payload: { email, name } }) {
sessionStorage.setItem('name', name);
sessionStorage.setItem('email', email);
return {
...state,
isLogin: true,
Expand Down

0 comments on commit 7f316e3

Please sign in to comment.