TRPC waiting until the query has completed
Hey. I've just found out about TRPC and I love it. However, I was wondering if there is a way to make it so the code below my query doesn't run until the query has completed, without having to make an external function or make use of a useeffect hook in order to use await?
Is there a property of some sort which I can use to stop the page from rendering?
The code below causes an infinite
signIn
loop due to the data
not being there on the initial page render. But, I can't check if !guilds.data
, because sometimes it wont return anything, due to an invalid token. Which means there is no good way to identify when to force a signIn
for the user.
13 Replies
edit:
this is what I went with.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
hmm interesting. Thanks. I'll have a look into that 🙂
This will be useful I suppose since
getGuilds
relies on accessToken
i should use getGuilds
in the onSuccess
event?Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
oh right okay, ill have a look into doing that as well. Thank you 🙂
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
If I understand correctly, this is the way to do this is:
When creating the context for the user, I find their access token and return it to them.
And then, I can use
ctx.session
to return the accessToken, and userInformation to the user:
My component/page
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Yep it works 🙂 Thank you very much for the help.
My usecase for
getSession
is to check if that specific user has access to the page (if they don't, then it will force them to login again and redirect them to a different page). This also would be used to protect my endpoints so people cant update/delete content which they don't have access for.Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Yep. That makes sense. Thanks a bunch!
I love TRPC, I am currently migrating to using it from using react/python backend, and it was such a pain to make each endpoint. Took alot of different files/code to do it, this makes it much simpler.
Wht vscode extension are you using to get the gui lsp?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View