mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
feat: add clerk auth support with convex (#548)
This commit is contained in:
@@ -3,7 +3,7 @@ import { createRouter as createTanStackRouter } from "@tanstack/react-router";
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import { routerWithQueryClient } from "@tanstack/react-router-with-query";
|
||||
import { ConvexQueryClient } from "@convex-dev/react-query";
|
||||
import { ConvexProvider } from "convex/react";
|
||||
import { ConvexProvider, ConvexReactClient } from "convex/react";
|
||||
import { routeTree } from "./routeTree.gen";
|
||||
import Loader from "./components/loader";
|
||||
import "./index.css";
|
||||
@@ -31,7 +31,11 @@ export function createRouter() {
|
||||
if (!CONVEX_URL) {
|
||||
console.error("missing envar VITE_CONVEX_URL");
|
||||
}
|
||||
const convexQueryClient = new ConvexQueryClient(CONVEX_URL);
|
||||
const convex = new ConvexReactClient(CONVEX_URL, {
|
||||
unsavedChangesWarning: false,
|
||||
});
|
||||
|
||||
const convexQueryClient = new ConvexQueryClient(convex);
|
||||
|
||||
const queryClient: QueryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -49,7 +53,7 @@ export function createRouter() {
|
||||
defaultPreload: "intent",
|
||||
defaultPendingComponent: () => <Loader />,
|
||||
defaultNotFoundComponent: () => <div>Not Found</div>,
|
||||
context: { queryClient },
|
||||
context: { queryClient, convexClient: convex, convexQueryClient },
|
||||
Wrap: ({ children }) => (
|
||||
<ConvexProvider client={convexQueryClient.convexClient}>
|
||||
{children}
|
||||
@@ -82,7 +86,7 @@ const trpcClient = createTRPCClient<AppRouter>({
|
||||
links: [
|
||||
httpBatchLink({
|
||||
url: `${import.meta.env.VITE_SERVER_URL}/trpc`,
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
fetch(url, options) {
|
||||
return fetch(url, {
|
||||
...options,
|
||||
|
||||
Reference in New Issue
Block a user