-
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
로그인페이지 및 auth router제작
- Loading branch information
Showing
15 changed files
with
232 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,31 @@ | ||
import React from 'react'; | ||
import { Route, Redirect } from 'react-router-dom'; | ||
import { useSelector } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { get } from '../../utils/snippet'; | ||
|
||
export default function AuthRoute({ component: Component, render, ...rest }) { | ||
const authSelector = useSelector(get('auth')); | ||
return ( | ||
<Route | ||
{...rest} | ||
render={(props) => (authSelector.isLogin ? ( | ||
render ? ( | ||
render(props) | ||
) : ( | ||
<Component {...props} /> | ||
) | ||
) : ( | ||
<Redirect | ||
to={{ pathname: '/', state: { from: props.location } }} | ||
/> | ||
))} | ||
/> | ||
); | ||
} | ||
|
||
AuthRoute.propTypes = { | ||
component: PropTypes.any, | ||
render: PropTypes.any, | ||
location: PropTypes.any, | ||
}; |
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 @@ | ||
export { default } from './AuthRoute'; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
export const QuestionMock = [ | ||
{ | ||
id: 1, | ||
|
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,68 @@ | ||
/* eslint-disable no-useless-escape */ | ||
import React, { useState } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { Redirect } from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
import { get } from '../../utils/snippet'; | ||
import { setLogin } from '../../store/Auth/auth'; | ||
import LoginApi from '../../repository/loginRepository'; | ||
|
||
const Wrapper = styled.div` | ||
height: 100vh; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
`; | ||
|
||
export default function LoginPage() { | ||
const dispatch = useDispatch(); | ||
const authSelector = useSelector(get('auth')); | ||
|
||
const [loginForm, setLoginForm] = useState({ | ||
email: '', | ||
password: '', | ||
}); | ||
|
||
const handleInput = (e) => { | ||
setLoginForm({ | ||
...loginForm, | ||
[e.target.name]: e.target.value, | ||
}); | ||
}; | ||
const handleLogin = () => { | ||
LoginApi(JSON.stringify(loginForm)).then((response) => { | ||
const user = JSON.stringify(response.data.email).replace(/\"/g, ''); | ||
dispatch(setLogin({ user })); | ||
}).catch(() => { | ||
alert('로그인 실패'); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Wrapper> | ||
{authSelector.isLogin && <Redirect to="/conference" />} | ||
<div> | ||
<h3>아이디</h3> | ||
<input | ||
placeholder="아이디(이메일)" | ||
value={loginForm.id} | ||
onChange={handleInput} | ||
name="email" | ||
/> | ||
</div> | ||
<div> | ||
<h3>비밀번호</h3> | ||
<input | ||
placeholder="비밀번호" | ||
value={loginForm.password} | ||
onChange={handleInput} | ||
name="password" | ||
type="password" | ||
/> | ||
</div> | ||
|
||
<button onClick={handleLogin} type="button">로그인</button> | ||
</Wrapper> | ||
); | ||
} |
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 @@ | ||
export { default } from './LoginPage'; |
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,10 @@ | ||
/* eslint-disable no-return-await */ | ||
import api from '../context/serverContext'; | ||
|
||
const LoginApi = async (param) => await api({ | ||
url: '/login', | ||
type: 'post', | ||
param, | ||
}); | ||
|
||
export default LoginApi; |
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,29 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
const authReducer = createSlice({ | ||
name: 'auth', | ||
initialState: { | ||
isLogin: false, | ||
user: '', | ||
}, | ||
reducers: { | ||
setLogin(state, { payload: { user } }) { | ||
return { | ||
...state, | ||
isLogin: true, | ||
user, | ||
}; | ||
}, | ||
setLogout(state) { | ||
return { | ||
...state, | ||
isLogin: false, | ||
user: '', | ||
}; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setLogin, setLogout } = authReducer.actions; | ||
|
||
export default authReducer.reducer; |
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