basir / mern-amazona

Build Ecommerce Like Amazon By MERN Stack
https://www.youtube.com/watch?v=ZjwBs3n7waY&list=PLeh2GWv22bmSQ9oBSYTd469_AQjPGpzyv
325 stars 242 forks source link

When editing User Profile it will say Invalid Admin Token #1

Open darrengeary opened 2 years ago

darrengeary commented 2 years ago

Admin Token should not be needed for standard user to edit profile.

meihdimtg commented 2 years ago

Me too :)

darrengeary commented 2 years ago

Yes I'm really struggling to see where it is calling isAdmin function

meihdimtg commented 2 years ago

Yeah, but the problem is the _id, on safari i have different error code. safari error: Cast to ObjectId failed for value "profile" (type string) at path "_id" for model "User" i have created demo account, i work one time after i have the same message ...

meihdimtg commented 2 years ago

I going to check next movie, i'm waiting to publish on heroku maybe after is work.

aminawinti commented 2 years ago

Got same error here guys, when updating profile for:

  1. admin, error: Cast to ObjectId failed for value "profile" (type string) at path "_id" for model "User"
  2. standard user, error: Invalid Admin Token

I'll dig in userRoutes put method and see if I can find a solution.

meihdimtg commented 2 years ago

i have download latest version of project, so it's work now, but i have new problem, with the Token, not the admin Token, i see the code and see:

export const isAuth = (req, res, next) => { const authorization = req.user; if (authorization) { const token = authorization.slice(7); jwt.verify(token, process.env.JWT_SECRET, (err, decode) => { if (err) { res.status(401).send({ message: 'Token Invalid' }); } else { req.user = decode; next(); } }); } else { res.status(401).send({ message: 'Aucun Token' }); } };

Authorization don't have data ! and if you call you don't have Token after you see error Token ! So, Basir not respond...

smitchof47 commented 2 years ago

1 day for fix this error ^^ "Cast to ObjectId failed for value "profile" (type string) at path "_id" for model "User""

change the order of profile route put it befor "/:id" route

PheelEu commented 2 years ago

still not working for me

naniiluja commented 1 year ago

Move .put "/profile" before .get "/:id"

PheelEu commented 1 year ago

Move .put "/profile" before .get "/:id"

Yes, can confirm this worked for me