json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Auth

Open mohammad-taheri1 opened this issue 2 years ago • 5 comments

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

mohammad-taheri1 avatar Feb 17 '23 14:02 mohammad-taheri1

/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.

ericnewton76 avatar Mar 21 '23 16:03 ericnewton76

The Problem using The way expressjs is with Options and it complete does not use the expand or embed relations

tiarralittle avatar Sep 28 '23 13:09 tiarralittle

https://github.com/jeremyben/json-server-auth look like it's what you are looking for and me too.

tiarralittle avatar Sep 28 '23 13:09 tiarralittle

?

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: @.***>

christinerobinson426 avatar Sep 28 '23 14:09 christinerobinson426

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`,
        },
      ],
    },
  }
}

wll8 avatar Jan 11 '24 08:01 wll8