Skip to content
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

Permissions #41

Open
MicahPotter opened this issue Oct 4, 2022 · 4 comments
Open

Permissions #41

MicahPotter opened this issue Oct 4, 2022 · 4 comments

Comments

@MicahPotter
Copy link

I'm not seeing a way to protect certain crud endpoints. Say a user needs to update their own information, but should not have permission to update another user's info. Is there a built in way to do that?

@baptadn
Copy link
Member

baptadn commented Oct 5, 2022

Hello @MicahPotter ! You can use the onRequest callback to plug your acl logic https://next-crud.js.org/api-docs/callbacks#onrequest

@mikerudge
Copy link

Hey @shinework

I have been trying to use the onRequest callback, and manipulating the query.

async onRequest(req, res, options?) {
    const query = req.query
    
    // Do some stuff to the query
    Object.assign(req.query, {
        where:  {...},
    });
    
    console.log(query) // The query has everything I would now expect
  
    // I now want next-crud to continue to do its thing with the manipulated query
   
    return req // Do we just return the req here? 
}

I am missing something obvious I know, but wondered if you could help with an example?

@mikerudge
Copy link

To clarify, I was looking for a way to automatically add a filter for certain models.

So I am hoping I can update the request query.where and then pass that back to the next-crud.

The req I have looks something like this:

const req = {
	baseUrl: "",
	originalUrl:
		"/api/users?where=%7B%22role%22%3A%7B%22%24eq%22%3A%22ADMIN%22%7D%7D&include=",

	params: { "0": "/api/users" },
	query: {
		where: '{"role":{"$eq":"ADMIN"}}',
		include: "",
		" nextcrud": ["users"],
	},
}

Do we need to update both the originalUrl and the query object?

@mikerudge
Copy link

Oh, sorry, looks like this is already being discussed in #44

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

3 participants