-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the problem
Split from #2051 after reading @benmccann's comment and #2051 (comment).
The real issue for me here is regarding authentication/authorization. A particularly common solution for this is Auth0. The new Open Source cool kid on the block is SuperTokens. When using Express middleware, solutions like these (and others) typically have a habit of adding data to the request object. For example, Auth0 gives us req.oidc, and SuperTokens gives us req.session. With this info we can determine if a user is authenticated and act accordingly.
According to Auth0, it's safer to handle these things on the backend. Consequently, for web apps, Auth0 recommends the Authorization Code Flow. A similar approach would need to be used for other libraries/tools/solutions.
Unfortunately, from what I can tell, Svelte Kit has no way of accessing the information that these tools provide on the backend, which means there's no way to protect your routes on the backend. I've been trying at this for 2 or 3 weeks now (as I've had time) and haven't found a practical or even a jank solution to this problem.
Describe the proposed solution
A simple solution would be to provide a way for data tacked onto the request object to be given to Svelte Kit so that its handle function and/or endpoints can read it. From the comment that I mentioned earlier from Ben, it seems like this is possible?
Alternatives considered
Theoretically, if someone obtained extensive knowledge about the internals of an auth solution, a "Svelte-Kit-friendly" approach could be crafted instead. But this is clearly impractical and would have to be done for each and every auth solution. The research has been exhausting for me and I've gotten nowhere.
Theoretically, life could also be easier if the existing auth solutions provided approaches that were more like functions that returned information? But again, that would have to be done for each solution, and I don't know how viable that is.
Invalid Alternatives
Just in case they're brought up...
1) I don't want to use Authorization Code Flow with PKCE, or any other browser-only solutions. If all of the approaches were equally secure, then this issue would not matter. But seeing as those familiar with auth highly recommend handling this stuff on the backend, it's unfair to require devs to sacrifice security just for the sake of preference. In some (if not many) cases, this approach would also thwart SSR.
2) Requiring devs to implement their own separate auth solutions that are Svelte-Kit-friendly is not a valid option either. User security is a big deal. So if a dev is lacking knowledge, and if solutions are available from people who have worked out many kinks and who continue to make improvements, then it makes more sense to use those.
Open to any valid Svelte-Kit-friendly solutions that get auth working on the backend though!
Importance
i cannot use SvelteKit without it
Additional Information
If it's of use, here's an example of using Auth0 with ExpressJS web apps: https://auth0.com/docs/quickstart/webapp/express. (This is imagined to be an actual web app, not a mere collection of backend APIs.)
And here's an example from SuperTokens: https://supertokens.com/docs/emailpassword/common-customizations/verify-session.
It seems Remix has their own solution for this problem too if it helps.