json-server
json-server copied to clipboard
Auth
Hi
I was working with this amazing package and suddenly it came to my mind:
Can we have default Auth routes? like
/auth/login
/auth/register
If it is possible, let me create it and add pr. Thanks
/auth/login and /auth/register (login and registering users) should be considered out-of-scope for this project
One could assert some basic authentication and authorization could be added though. Json-serevr is built on top of express, so there's easy ways to achieve that.
The Problem using The way expressjs is with Options and it complete does not use the expand or embed relations
https://github.com/jeremyben/json-server-auth look like it's what you are looking for and me too.
?
On Thu, Sep 28, 2023, 9:32 AM Tiarra Little @.***> wrote:
https://github.com/jeremyben/json-server-auth look like it's what you are looking for and me too.
— Reply to this email directly, view it on GitHub https://github.com/typicode/json-server/issues/1405#issuecomment-1739190332, or unsubscribe https://github.com/notifications/unsubscribe-auth/AESWQJVPGR4TCT2GALJFT73X4V4ADANCNFSM6AAAAAAU7QR7FU . You are receiving this because you are subscribed to this thread.Message ID: @.***>
https://github.com/typicode/json-server/issues/1338
Can hack json-server
module.exports = (util) => {
return {
api: {
// For example, permission checks can be created at all entry points
'use /' (req, res, next) {
if(req.headers.token === undefined) {
res.status(403).json({msg: `No permission`})
} else {
next()
}
},
// Intercepts any requests sent to db.json, and responses from db.josn
'patch /books/:id' (req, res, next) { // intercept config.db
req.body.a = `111` // Modify the data passed in by the user
next()
res.mm.resHandleJsonApi = async (arg) => {
arg.data.a = `222` // Modify the response, it will not be stored in db.json
return arg.resHandleJsonApi(arg)
}
},
},
db: {
books: [
{
id: 1,
title: `css`,
},
],
},
}
}