-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Enable Custom Express Server request
Data to Be Read by Svelte-Kit
(for Auth)
#4654
Comments
I honestly don’t think that’s something the kit team will resolve. There are scores of issues requesting similar functionality over the last few years and none of them ever provided a viable solution for those using express. We chose sapper and svelte 3 years ago to build out an e-commerce platform with deep express integration. The performance was better than the competition at the time, but now we are stuck using sapper and really dated versions of svelte. Currently we are considering abandoning svelte altogether given the incredibly frustrating experience we have faced attempting to migrate. We are not going serverless for numerous reasons and the number of hours we’ve wasted trying to integrate kit with our node server is heartbreaking. Unless I am deeply mistaken, there is no room for folks with an existing express backend in sveltekit’s future. I apologize in advance for the rant, but your issue gave me the clearest opportunity to vent my frustration. |
request
Data to Be Read by Svelte-Kit
request
Data to Be Read by Svelte-Kit
(for Auth)
I had a similar issue with Shopify Auth. One of the solutions I tried was creating a custom svelte-kit server using express. something like this. |
Yeah that was the problem I wanted to avoid, as I mentioned in the This is honestly a problem that often seems to be overlooked in SSR frameworks like Next.js, Nuxt.js, etc. Svelte Kit was close, but they still blocked out the ability to accomplish these kinds of things... leaving the problem to remain. Since this issue got added to |
While its not a solution, but I also had a situation where I needed to use existing
|
Unfortunately, that workaround doesn't quite do what I need it to do. I don't know what the rules are for updating the Your solution doesn't seem to "need" anything that comes from Express. (You could probably skip the polyfilling if you had info from Express. But you're still able to access/create the data you need without using Express.) Even so, thanks for sharing! Perhaps it might help someone else who stumbles across this issue. 🙏🏾 |
@ITenthusiasm - Now that #5778 (which implements #5748) is merged, and |
This is asking for a way to expose data from the underlying Express |
Thanks for checking in though! |
This should have been closed when #8171 was merged |
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 usreq.oidc
, and SuperTokens gives usreq.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 itshandle
function and/orendpoint
s 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.
The text was updated successfully, but these errors were encountered: