Commit 8118cdae authored by kusang96's avatar kusang96
Browse files

Merge remote-tracking branch 'origin/jaeyeon' into ourMaster

parents 58d63a89 0cef6d11
......@@ -11,7 +11,7 @@ function SubNav() {
useEffect(async () => {
try {
const response = await axios.get('/api/categories')
const response = await axios.get('/api/categories/main')
let list = []
Object.keys(response.data[0]).forEach((ele) => {
const url = ele.toLowerCase()
......
......@@ -35,7 +35,7 @@ function Login() {
try {
setError('')
const response=await axios.post('/api/auth/login', user)
handleLogin(response.data.userId)
handleLogin(response.data)
setSuccess(true)
} catch (error) {
catchErrors(error, setError)
......
import axios from "axios"
export function handleLogin(userId){
localStorage.setItem('loginStatus',userId)
export function handleLogin({userId,role,name}){
localStorage.setItem('id',userId)
localStorage.setItem('role',role)
localStorage.setItem('name',name)
}
export async function handleLogout(){
localStorage.removeItem('loginStatus')
localStorage.removeItem('id')
localStorage.removeItem('role')
localStorage.removeItem('name')
await axios.get('/api/auth/logout')
window.location.href='/'
}
export function isAuthenticated(){
const userId= localStorage.getItem('loginStatus')
const userId= localStorage.getItem('id')
if(userId){
return userId
} else{
......
......@@ -7,11 +7,11 @@ const login = async(req,res)=>{
const {id, password} =req.body
console.log(id,password)
try{
const user=await User.findOne({id}).select('+password')
const user=await User.findOne({id}).select('password role name')
console.log('u=',user)
if(!user){
return res.status(404).send(`${id}가 존재하지 않습니다.`)
}
}
const passwordMatch= await bcrypt.compare(password, user.password)
if(passwordMatch){
......@@ -23,7 +23,8 @@ const login = async(req,res)=>{
httpOnly:true,
secure:config.env ==='production'
})
res.json({userId:user._id})
res.json({userId:user._id, role: user.role, name: user.name})
}else{
res.status(401).send('비밀번호가 일치하지 않습니다.')
}
......
import Category from "../schemas/Category.js";
const getCategory = async (req, res) => {
console.log("dsadd=")
try {
const category = await Category.find({}, {_id: 0})
res.json(category)
......@@ -10,4 +11,16 @@ const getCategory = async (req, res) => {
}
}
export default { getCategory }
\ No newline at end of file
const getSubCategory=(req,res)=>{
}
const getsubId=(req,res,next,sub)=>{
const subcategory = await category.find({"Dress"})
console.log('sub=',sub)
next()
}
export default { getCategory , getsubId, getSubCategory}
\ No newline at end of file
......@@ -52,12 +52,10 @@ const getlist=(req,res)=>{
const categoryId = async (req, res, next, category) => {
try {
console.log(category)
const productslist = await Product.find({"main_category": `${category}`})
const productslist = await Product.find({main_category: category})
if (!productslist) {
res.status(404).send('상품을 찾을 수 없습니다.')
}
console.log("list=",productslist)
req.productslist = productslist
next()
} catch (error) {
......@@ -74,7 +72,7 @@ const subgetlist=(req,res)=>{
}
const subcategoryId = async (req, res, next, subcategory) => {
try {
const subproductslist = await Product.find({"sub_category":`${subcategory}`})
const subproductslist = await Product.find({sub_category:subcategory})
if (!subproductslist) {
res.status(404).send('상품을 찾을 수 없습니다.')
}
......
......@@ -5,7 +5,7 @@ import bcrypt from 'bcryptjs';
const signup = async (req, res) => {
const { name, number1, number2, id, password, tel } = req.body
const { name, number1, number2, id, password, tel ,role} = req.body
console.log(req.body)
try {
......@@ -27,7 +27,7 @@ const signup = async (req, res) => {
password: hash,
tel,
}).save()
await new Cart({ userId: newUser._id }).save()
await new Cart({ userId: newUser._id,role}).save()
console.log(newUser)
res.json(newUser)
......
......@@ -3,7 +3,12 @@ import categoryCtrl from "../controllers/category.controller.js";
const router = express.Router()
router.route('/')
router.route('/main')
.get(categoryCtrl.getCategory)
router.route('/sub/:sub')
.get(categoryCtrl.getSubCategory)
router.param('sub',categoryCtrl.getsubId)
export default router
\ No newline at end of file
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