Commit 3aa0a668 authored by seoyeon's avatar seoyeon
Browse files

0727

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