Commit 245ddecd authored by 우지원's avatar 우지원
Browse files

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

parents 4a23dcaa 3aa0a668
import axios from "axios"; import axios from "axios";
const getUser = async (payload) => { const getUser = async (payload) => {
const { data } = await axios.get("/api/user", payload); const { data } = await axios.post("/api/getUser", payload);
return data; return data;
}; };
......
...@@ -2,8 +2,10 @@ import { Link } from "react-router-dom"; ...@@ -2,8 +2,10 @@ import { Link } from "react-router-dom";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import userApi from "../../apis/user.api"; import userApi from "../../apis/user.api";
const userprofile = localStorage.getItem("user");
console.log(userprofile)
const INIT_USER = { const INIT_USER = {
id: '', id: userprofile,
name: '', name: '',
img: '', img: '',
} }
...@@ -11,14 +13,13 @@ const INIT_USER = { ...@@ -11,14 +13,13 @@ const INIT_USER = {
const HomeProfile = () => { const HomeProfile = () => {
const [user, setUser] = useState(INIT_USER) const [user, setUser] = useState(INIT_USER)
const id = localStorage.getItem('user'); async function getSetUser(userID) {
async function getUser(id) {
try { try {
// `/users/${userId}`랑 userId랑 같은지 확인 // `/users/${userId}`랑 userId랑 같은지 확인
const User = await userApi.getUser(id) console.log('userID',userID)
console.log(User) const data = await userApi.getUser({id: userID})
setUser(User.data) console.log(data)
setUser(data)
console.log(user) console.log(user)
} catch (error) { } catch (error) {
// catchErrors(error, setError) // catchErrors(error, setError)
...@@ -26,11 +27,12 @@ const HomeProfile = () => { ...@@ -26,11 +27,12 @@ const HomeProfile = () => {
} }
useEffect(() => { useEffect(() => {
getUser(id) console.log('예에에에에ㅔ에에')
}, [id]) getSetUser(userprofile)
}, [userprofile])
return ( return (
<Link to={`/profile/${id}`} className="text-decoration-none text-dark"> <Link to={`/profile/${user}`} className="text-decoration-none text-dark">
<form className="flex-column align-items-center justify-content-center m-2"> <form className="flex-column align-items-center justify-content-center m-2">
<div className="d-flex justify-content-center"> <div className="d-flex justify-content-center">
<img <img
......
...@@ -6,7 +6,7 @@ export function handleLogin(userId) { ...@@ -6,7 +6,7 @@ export function handleLogin(userId) {
export async function handleLogout() { export async function handleLogout() {
alert("로그아웃되었습니다.") alert("로그아웃되었습니다.")
localStorage.removeItem('loginStatus') localStorage.removeItem("user")
await axios.get('/api/auth/logout') await axios.get('/api/auth/logout')
window.location.href='/' window.location.href='/'
} }
......
...@@ -4,9 +4,12 @@ import config from '../config/app.config.js' ...@@ -4,9 +4,12 @@ import config from '../config/app.config.js'
import isLength from 'validator/lib/isLength.js' import isLength from 'validator/lib/isLength.js'
import bcrypt from "bcryptjs"; import bcrypt from "bcryptjs";
const user = async (req, res) => { const getUser = async (req, res) => {
console.log(req.body) console.log('유저가져왔다아아아ㅏㅇ:',req.body)
const user = await User.findAll({ where: { id: req.body } }); console.log('id:',req.body.id)
const id = req.body.id
const user = await User.findOne({ where: { id: id } });
console.log('user:',user)
req.json(user) req.json(user)
}; };
...@@ -85,7 +88,7 @@ const logout = (req, res) => { ...@@ -85,7 +88,7 @@ const logout = (req, res) => {
} }
export default { export default {
user, getUser,
login, login,
signup, signup,
logout, logout,
......
...@@ -3,7 +3,7 @@ import userCtrl from "../controllers/user.controller.js"; ...@@ -3,7 +3,7 @@ import userCtrl from "../controllers/user.controller.js";
const router = express.Router(); const router = express.Router();
router.route("/getUser").get(userCtrl.user); router.route("/getUser").post(userCtrl.getUser);
router.route("/login").post(userCtrl.login); router.route("/login").post(userCtrl.login);
router.route("/signup").post(userCtrl.signup); router.route("/signup").post(userCtrl.signup);
......
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