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

Feature Request: Svelte and SvelteKit SDK #903

Closed
Parables opened this issue Aug 26, 2022 · 30 comments · Fixed by #2182
Closed

Feature Request: Svelte and SvelteKit SDK #903

Parables opened this issue Aug 26, 2022 · 30 comments · Fixed by #2182
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request sdk SDK package

Comments

@Parables
Copy link

The Svelte community is growing faster than you think.

More and more people are pouring down into the awesomeness of this framework.

It would really help if we could get an official SDK with well-written documentation on how to use it.

@MelodicCrypter
Copy link
Contributor

MelodicCrypter commented Sep 1, 2022

I second this. I've been a React dev since, but when I used Svelte/Kit -- I'm already using it right now and will for all my future projects. I also sent a feedback on this one :) . This would be awesome if added. 🔥

P.S. my biggest struggle (SSR issues, etc) right now is with Apollo (client and svelte-apollo). Although I've managed to make some tweaks, but it would be so nice if you can provide internal implementations.

@elitan
Copy link
Contributor

elitan commented Sep 1, 2022

Do you have any links to existing Svelte SDKs similar to Nhost? It would be great for inspiration.

@jdahlborg
Copy link

@plmercereau plmercereau added sdk SDK package documentation Improvements or additions to documentation enhancement New feature or request labels Oct 11, 2022
@alexander-mart
Copy link
Contributor

https://github.com/nohea/enehana-nhost-sveltekit-auth

This example no longer work for now :(

@alexander-mart
Copy link
Contributor

I started thread for SvelteKit question:
https://discord.com/channels/552499021260914688/1038498070847045793

@nunopato nunopato self-assigned this Nov 6, 2022
@nunopato
Copy link
Contributor

nunopato commented Nov 6, 2022

We don't have a svelte SDK planned for now but we can try to have an example app working soon.

@kematzy
Copy link
Contributor

kematzy commented Dec 7, 2022

.

I am willing to assist on this if that is still required.

As a new Nhost user, I may require some Nhost related handholding. Possible?

@fungilation
Copy link

Bump on this. An example monorepo with 2 apps: sveltekit and nhost would be nice.

Because Sveltekit just went 1.0, and I see this blasphemy (at the end):

When creating a SvelteKit project you’ll be asked if you want to add TypeScript, ESLint, Prettier, Playwright (for end-to-end browser tests) and Vitest (for unit tests). Integration guides already exist for many popular projects — Tailwind and Supabase, for example.

@fungilation
Copy link

Hmm, to address this blasphemy:

The community-maintained svelte-add lets you add a growing list of other integrations with a single command.

@elitan
Copy link
Contributor

elitan commented Dec 15, 2022

Oh, nice that SvelteKit 1.0 was released. If anyone from our community wants to help us create a todo app with Nhost that would be great. It would be a perfect candidate for our examples/ folder.

@stale
Copy link

stale bot commented Jun 13, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 13, 2023
@stale stale bot closed this as completed Jun 20, 2023
@joshua1
Copy link

joshua1 commented Jul 21, 2023

@Stale bot taking matters into its own hands. This needs to be reopened and tracked . I am following the supabase example here https://github.com/huntabyte/sk-supabase-auth to see if it will work for nhost. Difference being supabase has helpers for sveltekit with which to create a serverside client (just like nhost has , but only for next.js) . I will feedback with the result here

@dbarrosop dbarrosop reopened this Jul 21, 2023
@stale stale bot removed the stale label Jul 21, 2023
@dbarrosop dbarrosop assigned onehassan and unassigned nunopato Jul 26, 2023
@gregoryforel
Copy link

Hi @onehassan @nunopato, is there any plan to work on a SvelteKit SDK in the coming weeks/months? I saw that the task was assigned to Hassan, but not sure if there is any progress made. This was requested a year ago, and since then I think the interest in SvelteKit has only grown! Most of us who used React and tried Svelte are reluctant to go back to React.

I tried to put something together reading the NextJS SDK code, and this and this, but I'm always stuck.
I wish I could help you develop the SDK, but I'm a hobbyist dev and facing my own limitations on this one.

Please don't make us use Supabase! :)

@onehassan
Copy link
Contributor

Hi @gregoryforel, this is next on my list. Most likely we will be adding another package that provides helpers for user authentication in SvelteKit. All the other functionality will still be provided by our JS sdk.

@gregoryforel
Copy link

Hi @gregoryforel, this is next on my list. Most likely we will be adding another package that provides helpers for user authentication in SvelteKit. All the other functionality will still be provided by our JS sdk.

This is great news! Can't wait to try a working SvelteKit repo :)

@fungilation
Copy link

Please don't make us use Supabase! :)

lol.

Is Next.js so bad? Just curious

@gregoryforel
Copy link

Please don't make us use Supabase! :)

lol.

Is Next.js so bad? Just curious

NextJS is good, it would be too easy to deny it just because SvelteKit, which is IMO superior, came along. You simply write more code in React, and I have yet to find a kind of application that could not be done with SvelteKit but can with NextJS.
React won the battle against Angular years ago, and most devs went all-in. Then Vue came along, Svelte, and all the others, but the market already had the React/NextJS inertia. I don't think any of the new frameworks/libs will dethrone React, but I can see some companies and startups choosing them to iterate quicker and make developers happier.
Having said that, I think a paradigm shift in Web development will dethrone React. Something of the likes of Flutter, .Net Maui, etc. Anything that allows back/front development and multiplatform with 1 language will be a winner.

@onehassan
Copy link
Contributor

onehassan commented Aug 23, 2023

@gregoryforel We have included a proper example for using Nhost with SvelteKit. Let us know if you have feedback/suggestions!

https://github.com/nhost/nhost/tree/main/examples/sveltekit

@fungilation
Copy link

https://github.com/nhost/nhost/blob/main/examples/sveltekit/src/lib/nhost-auth-sveltekit.js looks like an interesting adapter. Thanks for the example!

(I'm still on the fence with Svelte itself)

@gregoryforel
Copy link

@gregoryforel We have included a proper example for using Nhost with SvelteKit. Let us know if you have feedback/suggestions!

https://github.com/nhost/nhost/tree/main/examples/sveltekit

Thank you so much!

@shiftlabs1
Copy link

shiftlabs1 commented Sep 5, 2023

@gregoryforel We have included a proper example for using Nhost with SvelteKit. Let us know if you have feedback/suggestions!

https://github.com/nhost/nhost/tree/main/examples/sveltekit

This example confirms there is no way to use the nhost client server side like in sveltekit form actions running in +page.server.ts or am i missing something . I have tried implementing this for server side usage and with each use i get the error 'The state machine is not yet ready after 15 seconds.'.

Even with start property in config set to true and calling start here

nhost.auth.client.start({ initialSession: session })

This example is just an SPA mode example: A simple svelte SPA app would have sufficed . I was expecting a server Client at the very least , the type you have in the next.js example

@dbarrosop
Copy link
Member

The only thing the example confirms is that we are working on the examples. There are multitude of combinations of frameworks and mechanisms and we are doing our best to support and write examples for as many of them as possible. If any combination doesn't work for you it is best to report it, provide as much information as possible and be patient.

@gregoryforel
Copy link

@onehassan, @dbarrosop - Thank you for the example, it's a good starting point.

What would be great is having nHost work the Sveltekit way with SSR (even though Sveltekit can do SPA and SSG).
And not only Sveltekit, I might be wrong but if I recall, there aren't working examples of nHost with NextJS 13 with the new App router, or Remix.

SSR is becoming the norm, it makes routing easier and has other perks included.

I can't contribute directly on the nHost side because I simply lack the skills, however I put together a working example of SvelteKit and Pocketbase after watching a few tutorials, that I think would help you improve your example.

I reckon this example is exactly what nHost users are expecting: server-side authentication, SSR, etc.

I really don't want to come across as demanding, I just happen to think nHost is superior to Supabase, and once setup correctly, easier to use. I think nHost is lagging behind Supabase in terms of fully working starter kits that the community needs. Supabase is taking off and influencers start to make many examples, I'd love to see more of this with nHost. I understand that Supabase has a lof of funding though.

IMO, it's key for nHost to nail the examples. Thanks in advance!

@onehassan
Copy link
Contributor

@shiftlabs1 we've just released a new example project that showcases how to use the Nhost SDK running server-side with SvelteKit

You can find it here
https://github.com/nhost/nhost/tree/main/examples/quickstarts/sveltekit

Any questions or feedback are welcome as we want to improve this and make it easier for SvelteKit devs to use Nhost 🚀

@joshua1
Copy link

joshua1 commented Oct 11, 2023

@onehassan this server side example seems to require xstate , particularly the waitFor method. Since this is used within nhost, can that method alone be exposed, so we dont have to install xstate when our application does not make any use of it. (that method waitFor seems to be why its not been possible to instantaite the client serverside as it always returns null)

@shiftlabs1
Copy link

@onehassan this server side example seems to require xstate , particularly the waitFor method. Since this is used within nhost, can that method alone be exposed, so we dont have to install xstate when our application does not make any use of it. (that method waitFor seems to be why its not been possible to instantaite the client serverside as it always returns null)

Similar observation here , I am not sure i want to install xstate . what is the alternative here @onehassan ?

@onehassan
Copy link
Contributor

We are going to add another method to our SDK that hides that part. Very soon you will be able to do
await nhost.auth.initWithSession({ initialSession })

@shiftlabs1
Copy link

We are going to add another method to our SDK that hides that part. Very soon you will be able to do await nhost.auth.initWithSession({ initialSession })

That will be very helpful .

@nohea
Copy link

nohea commented Oct 19, 2023

@onehassan very cool work. I'm reading thru the code. Is it the case that your examples all execute the Nhost client via kit server (SSR)? The Nhost session is authenticated server-side, and the cookie is serialized to browser cookie 'nhostSession'?

I'm just trying to wrap my head around it, because my app, i've done all the Nhost auth browser-side (CSR) using nhost.auth.onAuthStateChanged/onTokenChanged , and sometimes manually pass the JWT as a formData param if i want it on the SSR side. I want to use your technique for SSR, it would be simpler than manual passing. I may keep my login pages CSR but pass JWT to server load() your way. 🙂

@onehassan
Copy link
Contributor

onehassan commented Oct 19, 2023

@nohea The authentication in the example happens server-side (not SSR) except for when using a security (webauthn).

Take a look at the webauthn signin page, you'll see that indeed we do the authentication on the client and then we save the session in a cookie that's accessible to the server. You can do the same thing but with an email and a password.

After that you can use the getNhost(cookies) in the server load functions and form actions.

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

Successfully merging a pull request may close this issue.