-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you use Clerk with tRPC successfully? #1702
Comments
@tmcw Geniune question as I'm interested in using
Given that this is an issue that's been given priority by the company, I trust that this is a legitimate concern. I'm just trying to understand how this is such a show-stopper. |
My understanding so far is that basically Clerk refreshes tokens very often, and it does so - when I'm using Remix - by having a custom loader, returning an interstitial response, which triggers a token refresh. This has problems of its own, but - when I'm using tRPC as well, when a request fails, right now it triggers an interstitial - the tRPC endpoint returns HTML instead of JSON and breaks the site. I could treat that as failable, but that leaves open the question of how the token will get refreshed. We haven't really found a reliable pattern for using Clerk with tRPC or API routes in general, and I haven't seen one suggested (at least for Remix) anywhere. So like you could let your API routes 400, but they'll continue to 400 and you won't get a token refresh like you should. |
I'm also having this issue. Using |
I'm not sure that the prioritized label is much reason for hope, my other issue has been stalled for |
Hello @tmcw I took a look at it, and indeed the |
Hello @kmkinney, I have not checked out yet with Next.js but we have a starter (https://github.com/clerkinc/t3-turbo-and-clerk) that you can take a look in case something is not configured properly in your app. |
Hello! 👋 |
@octoper this is absoltely not resolved – next app router + trpc + clerk is broken |
i agree this is not resolved at all, integrating clerk into a next 14 app with the app dir and using trpc throws cryptic errors regularly. right now im getting something in the likes of "cannot reading property of undefined (reading resolve)" . given that there is not description other than "add public routes to |
On our deployed netlify site, we always get getAuth() error when refreshing a page that uses a mutation or query. Those queries only work if you first navigate to another page and then to the page that uses that TRPC functionality, pretty broken:
|
Second this, clerk + app router + trpc is completely broken The page doesn't load and just keeps refreshing. Also getting random 401 errors even though trpc routes are set to public |
I'm about to setup next 14 + clerk + trpc and came across this issue. From what I can tell, there is a working example here for how to setup the TRPC context here: https://github.com/clerk/t3-turbo-and-clerk/blob/main/packages/api/src/context.ts It seems important to distinguish between the See this file for more: https://github.com/clerk/javascript/blob/main/packages/nextjs/src/server/getAuth.ts |
Is there any working example of how we can intergate it similair to this example: https://github.com/clerk/t3-turbo-and-clerk/blob/main/packages/api/src/context.ts but using the Next JS App Router and publicRoutes in middleware.ts? |
the publicRoutes option was not working for me, and I could not remove the So I just used the ignoredRoutes options to make some of my trpc endpoints public. It's working for me so far.
|
Hi All, I got this working smoothly in my application. I created a gist with the basics of how to do it: https://gist.github.com/mkcode/a590d1c8f7b0a37b8299965de7f7e958 |
Hello and thank you all for your patience. The interstitial mechanism in previous versions was indeed causing issues like the ones you've described. To address this, we have completely replaced it in our latest Core 2 release with a new mechanism to mitigate such issues. We advise updating to the latest major versions: either How to upgrade Remix to Core 2: https://clerk.com/docs/upgrade-guides/core-2/remix |
We've been using Clerk with tRPC and Remix. So our application makes requests to tRPC in the usual way, and I try get get auth like this:
This works at first but is not actually good at all: the
getAuth
method in Clerk makes a pretty hard assumption that it can throw an error and present an interstitial page. Which in a tRPC context makes no sense - you're doing an API request, and getting back a HTML page instead of JSON isn't going to work.So, we get crashes in prod and pretty polluted logs. What's the right way to do this? As it is, I don't see how to make Clerk work with tRPC, to get a user's auth from an API request and not break the API endpoint.
The text was updated successfully, but these errors were encountered: