Skip to content

Auth #1405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mohammad-taheri1 opened this issue Feb 17, 2023 · 5 comments
Open

Auth #1405

mohammad-taheri1 opened this issue Feb 17, 2023 · 5 comments

Comments

@mohammad-taheri1
Copy link

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

@ericnewton76
Copy link
Contributor

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

@tiarralittle
Copy link

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

@tiarralittle
Copy link

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

@christinerobinson426
Copy link

christinerobinson426 commented Sep 28, 2023 via email

@wll8
Copy link
Contributor

wll8 commented Jan 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants