Commit 4a23dcaa authored by 우지원's avatar 우지원
Browse files

Merge remote-tracking branch 'origin/seoyeon2' into jiweon827

parents 6d97fb5a ac15b407
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { handleLogout } from '../context/auth'
const Header = () => { const Header = () => {
return ( return (
<div> <div>
...@@ -8,9 +10,9 @@ const Header = () => { ...@@ -8,9 +10,9 @@ const Header = () => {
> >
<div className="d-flex justify-content-end"> <div className="d-flex justify-content-end">
<div> <div>
<Link to="/user"> <Link to="/user">
<img src="/BORA.png" style={{ width: '160px' }} /> <img src="/BORA.png" style={{ width: '160px' }} />
</Link> </Link>
</div> </div>
<button <button
type="button" type="button"
...@@ -18,7 +20,7 @@ const Header = () => { ...@@ -18,7 +20,7 @@ const Header = () => {
data-bs-toggle="modal" data-bs-toggle="modal"
data-bs-target="#logout" data-bs-target="#logout"
style={{ style={{
height: '30px', height: '30px',
backgroundColor: '#E0CEE8', backgroundColor: '#E0CEE8',
color: 'black', color: 'black',
border: '1px #E0CEE8', border: '1px #E0CEE8',
...@@ -48,11 +50,16 @@ const Header = () => { ...@@ -48,11 +50,16 @@ const Header = () => {
</div> </div>
<div className="row mb-3"> <div className="row mb-3">
<div className="d-flex justify-content-evenly"> <div className="d-flex justify-content-evenly">
{/* <Link to="/user"> */} <Link to="/" className="col-2 p-1 btn btn-primary">
<button type="submit" className="col-2 p-1 btn btn-primary"> <button
type="submit"
className="btn btn-primary"
onClick={() => handleLogout()}
data-bs-dismiss="modal"
>
</button> </button>
{/* </Link> */} </Link>
<button <button
type="submit" type="submit"
className="col-2 p-1 btn btn-primary" className="col-2 p-1 btn btn-primary"
......
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { Redirect } from 'react-router-dom' import { Redirect } from 'react-router-dom'
import userApi from '../apis/user.api' import userApi from '../apis/user.api'
// import { useAuth } from '../context/auth_context'
import catchErrors from "../context/catchError"; import catchErrors from "../context/catchError";
import { handleLogin } from '../context/auth';
const INIT_USER = { const INIT_USER = {
email: '', email: '',
password: '', password: '',
...@@ -33,6 +33,7 @@ const Login = () => { ...@@ -33,6 +33,7 @@ const Login = () => {
// setError(""); // setError("");
const data = await userApi.login(user) const data = await userApi.login(user)
console.log(data) console.log(data)
handleLogin(data.id)
setSuccess(true) setSuccess(true)
} catch (error) { } catch (error) {
console.log('error in login', error) console.log('error in login', error)
......
import axios from 'axios'
export function handleLogin(userId) {
localStorage.setItem("user", userId)
}
export async function handleLogout() {
alert("로그아웃되었습니다.")
localStorage.removeItem('loginStatus')
await axios.get('/api/auth/logout')
window.location.href='/'
}
export function isAuthenticated() {
const userId = localStorage.getItem('loginStatus')
if (userId) {
return userId
}else{
return false
}
}
...@@ -79,8 +79,14 @@ const signup = async (req, res) => { ...@@ -79,8 +79,14 @@ const signup = async (req, res) => {
} }
} }
const logout = (req, res) => {
res.clearCookie('token')
res.send('Logout Successful')
}
export default { export default {
user, user,
login, login,
signup, signup,
logout,
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment