rutenisraila
rutenisrailaβ€’16mo ago

Can't get users in Convex functions

Hey guys, I'm trying to add more fields into my user object, but when I try to return I can't seem to get the data. I followed the docs for working with users in Functions here: https://docs.convex.dev/auth/functions-auth Attaching some screenshots:
No description
No description
16 Replies
rutenisraila
rutenisrailaOPβ€’16mo ago
my suspicion is that the user is not even stored as the users table is empty (I took the example from the docs)
No description
No description
jamwt
jamwtβ€’16mo ago
yeah, users aren't being stored. definitely first step is making sure you're getting that table populated as verified in your dashboard
Michal Srb
Michal Srbβ€’16mo ago
@rutenisraila make sure you're calling the store mutation from your app: https://docs.convex.dev/auth/database-auth#calling-storeuser-from-react
Storing Users in the Convex Database | Convex Developer Hub
You might want to have a centralized place that stores information about the
joe πŸ‡ͺπŸ‡¬πŸ—£πŸ”₯πŸ”₯
I followed this guide down to the T and I still con't find any authenticated users in my database
Michal Srb
Michal Srbβ€’16mo ago
@joe πŸ‡ͺπŸ‡¬πŸ—£πŸ”₯πŸ”₯ if you have the same problem make sure every step works. You can 1. console.log after the line const id = await storeUser(); on the client to check that the mutation is getting invoked, 2. console.log inside the mutation to make sure the server is processing it 3. Check the dashboard for data and logs
joe πŸ‡ͺπŸ‡¬πŸ—£πŸ”₯πŸ”₯
I get null unfortunatrely and I don't understand why
Michal Srb
Michal Srbβ€’16mo ago
Where do you get null ? Can you share your code?
joe πŸ‡ͺπŸ‡¬πŸ—£πŸ”₯πŸ”₯
However I am technically logged in even though the is doesn't show
Michal Srb
Michal Srbβ€’16mo ago
What's userId on line 27? And what do you get when you console.log in the storeUser mutation?
joe πŸ‡ͺπŸ‡¬πŸ—£πŸ”₯πŸ”₯
I don’t get anything when I do I get null
Michal Srb
Michal Srbβ€’16mo ago
@joe πŸ‡ͺπŸ‡¬πŸ—£πŸ”₯πŸ”₯ have you checked your logs on the Convex dashboard? Is your storeUser mutation getting called when you test the UI? Also have you checked the browser developer tools? Do you get any errors there about authentication?
joe πŸ‡ͺπŸ‡¬πŸ—£πŸ”₯πŸ”₯
No its not called
rutenisraila
rutenisrailaOPβ€’16mo ago
hi, I can confirm that the issue was on my end. I was not calling the storeUser mutation after I changed the layout around πŸ€¦β€β™‚οΈ thanks for the support guys
joe πŸ‡ͺπŸ‡¬πŸ—£πŸ”₯πŸ”₯
In the frontend or backend?
rutenisraila
rutenisrailaOPβ€’16mo ago
@joe πŸ‡ͺπŸ‡¬πŸ—£πŸ”₯πŸ”₯ for me the issue was very simple, the hook that initializes the storeUser mutation wasn't even called after an user enters a page that's protected with auth. I don't think it's a good way to store users anyway, I probably should use a callback for the clerk form, for now I'm just playing around with clerk so wanted a quick way to get started. hooks are always called on the frontend, but I can imagine you can call convex mutations on the backend too

Did you find this page helpful?