Message from JavaScript discussions
January 2018
— New Year Sale! Every Programming Course is 93% off!
https://reactdom.com/sale
Yo guys, i have express running and i am looking for something on top of it for creating solid api (with auth also), what to do?
— Why do you need something on top of it?
— Because i don't want to reinvent the wheel? How about jwt?
— It's not alot of code either way
— Well if I can rely on a production ready plugin, why not?
—
// require auth for all pages:
app.use((req, res, next) =>
db.authed(req.token).then(isAuthed =>
isAuthed
? next()
: res.json(authNeededError)));
// Single path:
app.get('/user/:id', (req, res) =>
db.user(req.params.id).then(user =>
user
? res.json(user)
: res.json(missingUserError)));
— Just remember DRY principles, and you'll write very little
— Well there are standards for that token.. Having something that layers this thing for you may be useful. My objective is build a complete frontend app (vuejs) that relies only on stateless API endpoints (even the login). Is that login into token the right way?
— Yes, you can use jwt for stateless login
— But you'll need to store users themselves
— So that'll obviously be stateful