Help migrating to use withUser() from convex-helpers and questions regarding the library
Hello, so i recently started migrating over to use some of the nice helpers etc. that convex-helpers brings.
I started with trying to refactor the way i handle auth and getting my user object, and ran into some minor issues, that raised some questions when using withUser() and useQuery() in a react component.
Here are some code for context, and easier understanding. Questions are listed below the code snippets
3 Replies
How i utilize it in my AuthProvider:
Questions:
1. How might one properly handle the error thrown from
getUserByTokenIdentifier(ctx)
because i can't just wrap the useQuery() in a try catch in the react component, as far as im concerned. Couldn't find any examples on this.
2. As it can be seen, the way i get around the query throwing an error, is by using isAuthenticated in the args on the query in my auth-provider
and skip it if its false. But wondering if there would be a smarter way of doing this, so i dont have to import useConvexAuth() everywhere i'd like to call a useQuery on query that utilizes withUser(), couldn't find any stack posts on how to build a custom useQuery() to go with a custom query like withUser()You usually want to use the
<Authenticated>
component to wrap any component that needs to call authenticated queries
Like
Ahh thanks Lee. This makes sense, i've missed the obvious here. Makes a lot of sense just wrapping my auth layout in my router, and all children routes that uses route. So the query would never run or happen.