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

Pass request to withMiddlewareAuth's isPermitted function #308

Closed
413n opened this issue Oct 13, 2022 · 3 comments · Fixed by #364
Closed

Pass request to withMiddlewareAuth's isPermitted function #308

413n opened this issue Oct 13, 2022 · 3 comments · Fixed by #364
Labels
enhancement New feature or request

Comments

@413n
Copy link

413n commented Oct 13, 2022

Feature request

Is your feature request related to a problem? Please describe.

I like the functionality of the withMiddlewareAuth helper, but in my use case I'm a bit limited. I would like to have multiple paths where I check the user authentication and for each I would like to check for a different user role.

Describe the solution you'd like

Referring to the following code, I would suggest to pass the request in the isPermitted function, so that we could check also for the url and be more specific.

https://github.com/supabase/auth-helpers/blob/main/examples/nextjs/middleware.ts#L1-L15

@413n 413n added the enhancement New feature or request label Oct 13, 2022
@NanoCode012
Copy link

NanoCode012 commented Oct 17, 2022

Yes! I have the same use case (check if user has role to access certain page). I used to do it via getServerSideProp, but it is inefficient and doesn't allow page caching.

With the new 12.2 nextjs middleware, we could use a single middleware to check, so it's faster.

The lines to change should be:

isPermitted: (user: User) => Promise<boolean>;

and
!(await options.authGuard.isPermitted(authResult.user))

I may open a PR targeting the 0.2.9 tag as I'm still using Supabase v1. However, I'm not sure which branch I should target to in my PR.

@NanoCode012
Copy link

Sorry for my late follow up, I have written the code for 0.2.9, but it should also be applicable to latest main branch also with some modification.

NanoCode012@93405a2

Changes from 0.2.9: @supabase/[email protected]:supabase-auth-helpers:feat/add-middleware-req

If someone could point me to how I could also have this update for Supabase v1, that'd be great. If not, please tell me so I could adapt the code for latest main branch.

@NanoCode012
Copy link

I just saw a new PR #364 which would solve this issue. Looking forward to it!

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

Successfully merging a pull request may close this issue.

2 participants