markjaquith / clerk-sveltekit

Clerk adapter for SvelteKit
Other
128 stars 19 forks source link

Get user/session data in server pages. #30

Closed brad-j closed 7 months ago

brad-j commented 7 months ago

Hello friend!

Firstly, thank you for this awesome library! I was able to get auth working in minutes and I pretty much have no idea what I'm doing.

With that, I'm not a dev, more of a hobbyist (this is the first issue I've ever written) so I'm probably way off and missing something that may be simple so feel free to tell me to kick rocks and go learn more about everything 😅.

Basically, a user will enter credentials (api_key and api_secret) into a form where I will save them using Vercel KV and in order to do that, I need their Clerk user.id. Right now I'm doing this in a super janky way by passing a hidden form field to my +page.server.ts like so:

<ClerkLoaded let:clerk>
    <input type="hidden" name="user_id" value={clerk?.user?.id} />
</ClerkLoaded>

It works and I'm using this in a few places, but I would like things to be more DRY and centralize my API calls. I noticed in the CLerk docs helpers like auth() and currentUser() which I assume are 'server' things since they're used in Nexts' app router. Is there something similar for this library? Do I need to look more into the ClerkJS library for answers?

Again, thanks for making this, and if this all makes no sense, feel free to close without comment!! 🙌🏽

UPDATE: I'm an idiot and just realized that I can get it from locals. Sorry for the bother! 🤦🏾

markjaquith commented 7 months ago

Great question! And you're right—getting it from locals is the way to do it.

I need to document that so that's clear.

Happy the library is working well for you. 🙌🏼