Giter VIP home page Giter VIP logo

Comments (10)

calvinKG avatar calvinKG commented on July 3, 2024 1

@LuizHAP

Your missing the isAuthenticated function that need to be added for each call to our API

From the tutorial " The last piece is to update our server.js file to include the passport package, initialize it with our express app, and call the isAuthenticated function for each call to our API. Open up server.js and update it as follows."

image

from beerlocker.

TheFive avatar TheFive commented on July 3, 2024

Hi Calvin,

the error indicates, that the authorization was not done correctly. Typically the req.user is set during the auth process.
May be just the authorization when you try to post the data is missing ?

Christoph

from beerlocker.

LuizHAP avatar LuizHAP commented on July 3, 2024

@TheFive i get the same error
error1
error2

from beerlocker.

TheFive avatar TheFive commented on July 3, 2024

wich beerlocker server are you working with 1,2,3...

from beerlocker.

LuizHAP avatar LuizHAP commented on July 3, 2024

@TheFive 3.2

from beerlocker.

TheFive avatar TheFive commented on July 3, 2024

you should add more information, when the error occurs (which version, which step in the blog you are evaluating).
Just a hint, where you can search. In the auth file, the user is taken from the database:
https://github.com/scottksmith95/beerlocker/tree/master/beerlocker-3.2/controllers
The function User.findOne retrieves the users from the database.
just add a console.log(user) in line 10, and you can see, what the result is.

(i assume, there is no user, so req.user is NULL at the stage, where the error occurs)

from beerlocker.

TheFive avatar TheFive commented on July 3, 2024

Thats typically, how i learn, put as much console.log in the source as you need to understand, what is going on.

from beerlocker.

LuizHAP avatar LuizHAP commented on July 3, 2024

@TheFive Ok. I put one user, and i can get them when i GET /api/users

[
  {
    "_id": "59166bf3d4de2b11707adbd8",
    "username": "luiz",
    "password": "$2a$05$JoE8wWw1uZ5eAC8w26PYzudMmRdj8.G3sAnU7fU5sHKsNe613GEta",
    "__v": 0
  }
]

When i can GET /api/beers, catch that error above. I don't understand how i can use that authentication.

from beerlocker.

calvinKG avatar calvinKG commented on July 3, 2024

Thanks @TheFive for the head-up

from beerlocker.

rohaanuv avatar rohaanuv commented on July 3, 2024

I get this error at frontend. It causes due to, it is not executing state means isAuthenticated unlike this const { user, token } = isAuthenticated();
just add 'isAuthenticated()' in event like submit, It works !!
For backend all private or protected routes must include isSignedIn, isAuthenticated, or specific user group auth, middleware must include

from beerlocker.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.