@wopr-network/platform-ui-core 1.22.2 → 1.22.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/trpc.tsx +10 -4
package/package.json
CHANGED
package/src/lib/trpc.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
4
|
-
import { createTRPCClient,
|
|
4
|
+
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
5
5
|
import { createTRPCReact } from "@trpc/react-query";
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
import { PLATFORM_BASE_URL } from "./api-config";
|
|
@@ -14,7 +14,13 @@ export const trpc = createTRPCReact<AppRouter>();
|
|
|
14
14
|
async function trpcFetchWithAuth(url: RequestInfo | URL, options?: RequestInit) {
|
|
15
15
|
const res = await fetch(url, { ...options, credentials: "include" });
|
|
16
16
|
if (res.status === 401) {
|
|
17
|
-
|
|
17
|
+
// On login page, don't throw — let the batch continue so public queries
|
|
18
|
+
// (like enabledSocialProviders) resolve alongside failing auth queries.
|
|
19
|
+
const onLoginPage =
|
|
20
|
+
typeof window !== "undefined" && window.location.pathname.startsWith("/login");
|
|
21
|
+
if (!onLoginPage) {
|
|
22
|
+
handleUnauthorized();
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
return res;
|
|
20
26
|
}
|
|
@@ -25,7 +31,7 @@ async function trpcFetchWithAuth(url: RequestInfo | URL, options?: RequestInit)
|
|
|
25
31
|
*/
|
|
26
32
|
export const trpcVanilla = createTRPCClient<AppRouter>({
|
|
27
33
|
links: [
|
|
28
|
-
|
|
34
|
+
httpBatchLink({
|
|
29
35
|
url: `${PLATFORM_BASE_URL}/trpc`,
|
|
30
36
|
fetch: trpcFetchWithAuth,
|
|
31
37
|
headers() {
|
|
@@ -76,7 +82,7 @@ export function TRPCProvider({
|
|
|
76
82
|
const [trpcClient] = useState(() =>
|
|
77
83
|
trpc.createClient({
|
|
78
84
|
links: [
|
|
79
|
-
|
|
85
|
+
httpBatchLink({
|
|
80
86
|
url: `${PLATFORM_BASE_URL}/trpc`,
|
|
81
87
|
fetch: trpcFetchWithAuth,
|
|
82
88
|
headers() {
|