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>
...@@ -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