#Authorization, best practice in Remix.run

1 messages · Page 1 of 1 (latest)

frigid sluice
#

Hi there,

I have been working on side project in Remix.run. And I need authorization. I cannot find any resource or documentation on the web. For auth, there is remix-auth package, but for authorization nothing. Currently, for each page/route I'm checking in loader if the user has authorization to access that route, but this is too verbose. Any best practice for this?

hollow wagon
#

Hello, yes checking the authorization in the loader is the current best way to do it.
In a futur version of remix, middleware will be added to minimize this kind of work.
You can find more information in the RFC about middleware : https://github.com/remix-run/remix/discussions/7642

GitHub

Route middleware are functions that can inspect the request before the app runs and modify the response after the app is ready to respond. Proposal This supersedes remix-run/react-router#9566. Midd...

next dirge
frigid sluice
next dirge
#

But my suggestion still stands but for whatever runtime you’re looking to use. The only way you couldn’t use my suggestion is if you’re building remix as a SPA using only clientLoaders and client actions

tawny estuary
#

authentication is "easy" to de generacally
but authorization can not always be done this way, especially in Remix without middlewares. Personnaly I don't mind doing specific authorization for each endpoint (each loader and each action), but i'll think i'll require something to ensure that authorization was not forgotten

neat blade
#

i do smth like requireUser function and return the user and if i want user object i can just have it from there

onyx halo
frigid sluice
onyx halo
#

Ahh sorry

cobalt cloud
#

In my experience, it’s better to just write functions where you can validate access to a route or resource and then call them when needed

frigid sluice
#

I get it now, and will do what @cobalt cloud said...