Closed cengizhanhakan closed 9 months ago
Code example
useEffect(() => { if (isLoaded) sendUserData() // eslint-disable-next-line react-hooks/exhaustive-deps }, [isLoaded]);
Hi @cengizhanhakan - could you provide a minimal reproduction for us to look into?
Hi @jescalan
You can check the website: https://strcalc.vercel.app
hi @jescalan, any updates?
Hi! Sorry for the delayed response. A link to your production website is not a minimal reproduction. We have a guide here on how to create a minimal reproduction, hopefully this is helpful! Sorry for not linking it before.
hi @jescalan, I hope this is good enough. https://github.com/cengizhanhakan/clerk-repro https://clerk-repro-1l2n9zzwf-recipecart.vercel.app/
hello @cengizhanhakan
visiting your https://clerk-repro-1l2n9zzwf-recipecart.vercel.app/ and executing a sign-in I can see that isLoaded
is updated based on the logs:
What is the expected the behavior you are trying to achieve using the isLoaded
? If your issue is the stale no user message on the page you should either depend on the <SignedIn/>
, <SignedOut/>
Clerk controls to render authenticated / un-authenticated parts of the page or use the const {user} = useUser()
effect on your current example instead of the const {user} = useClerk()
.
hi @dimkl Thank you for the comment. The problem only occurs on iOS. Steps to reproduce:
Hi team, we're still waiting on a response here.
Hello @cengizhanhakan @pakaplace, I've tried to reproduce the issue in multiple versions of iOS using both Chrome and Safari. However, based on the logs on https://clerk-repro-1l2n9zzwf-recipecart.vercel.app/, everything seems to be working as expected. Can you please confirm if you are still encountering that issue?
Hello @octoper After doing some testing on real devices. I will update here.
Hello! 👋 Please let me know if the issue still exists after testing on real devices. Additionally, to keep our GitHub issues organized, if there's no response within the next 7 days, I will consider the issue resolved and close it. Feel free to reopen it or reach out for further assistance. Thanks! 🚀
Hi @octoper, the issue stopped happening for us on ios devices about a month ago.
However, I was hoping you could suggest a better pattern on fetching user data from our external backend. We have a user table in our database that stores subscription data. In our next.js frontend, after waiting for isLoaded
to be true, we call our API to fetch user subscription data.
Once user data is loaded, then we render the page the user is trying to navigate to. You can see our parent component where we do the fetching in this reproduction: https://github.com/cengizhanhakan/clerk-repro/blob/main/src/pages/layout.tsx
I'd like to fetch this user data before the page loads so it doesn't slow down our app or affect our SEO. Could this be done from the middelware or should it be done from getServerSideProps? I also thought about using the webhooks. We would have to update the clerk webhooks every time there's an update to a user's info or stripe subscription, I imagine, which seems like a lot of work.
Closing this issue out as it appears to be resolved, but please feel free to keep the discussion going! I am sure that @octoper will respond here soon ✨
Hello @pakaplace , I'm glad to hear that your issue has been fixed.
Answering your other question, the most preferred and optimal way to sync data on your end is by using Webhooks. We have a straightforward guide on how to do it, which you can find here: Sync Clerk data to your backend with webhooks. This solution is the most optimal as you will only update the user on your end when the user is actually updated. Other solutions, like the one you currently have or the getServerSideProps
solution, could result in additional queries in your database as you would always update the user on every request, even if the data didn't change at all.
Package + Version
@clerk/nextjs
= 4.23.2Dependencies + versions
Provide a json with the dependencies used in your project (copy paste from yarn.lock / package-lock.json) or a github project / template that reproduces the issue.
*Include the @clerk/ packages and their versions!**
Example:
Browser/OS
iOS 16.3.1 / Safari / Chrome
Description
Describe your issue in detail, a demo repository or a sandbox would be great.
After logging in with Clerk, isLoaded variable from the useUser hook doesn't change and isn't able to trigger the useEffect we have.