Hello there! Am using supabase and sveltekit for m...
# help
d
Hello there! Am using supabase and sveltekit for my project and works all fine but there's a problem with me...,Whenever user sign's in (through sign in function ,for now its github) they get signed in properly but their session or data doesnt reflect on client side in realtime instantly i.e in browser, I mean when I console.log user data it shows null but when I refresh page then it shows user session and all properly..,This is not a big problem though ,But For user it can be frustating that they cant see them signed in! Is there any way that it shows the auth activity changes instantly on Authchange? Plz help me as am little new on working supabase with svelte πŸ™‚
n
Hello @Devr! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
b
hey devr, are you waiting for the promise in the auth function?
n
Devr (2022-03-24)
g
If local storage has not been set up then when you first get to page auth.user() will be null. After supabase processes things, then you will have a user object. You can use auth.onAuthStateChange to see the signin event. Putting await on auth.user() will not help as it is a sync function and just returns the user object in memory. Coming back from a signIn redirect.
Refreshing page (user object is now in local storage)
d
No..,
Hey thanks to reply.,Ill see if it worksπŸ‘
Sry but it doesnt work 😦 , maybe i've done something wrong can u share a piece of code about that pls?
g
I use sveltekit for my real code, but too complex to post user flow. I do everything client side, no server involved though. I have a test app in just js I used for the above. If you are using sveltekit with SSR then things will likely work differently.
Copy code
console.log('user at start',supabase.auth.user())
    supabase.auth.onAuthStateChange((event, session) => {
        console.log('user in auth change', event, session.user)
    })
Is what generated the code above when returning from sign in and then refreshing the screen, but it is pure client only.
This seems to be a good overall example of sveltekit https://github.com/robots4life/val
Here is a long discussion on sveltekit auth with SSR https://github.com/supabase/supabase/discussions/5218
d
Ok,thanks πŸ‘ Ill check this out
b
@Devr did you ever get something figured out here? Would love to see how this actually gets implemented in the full app.