Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 371x 179x 332x 149x 3x 146x 146x 146x 146x 146x 146x 146x | import React from "react";
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
import { TRPCClientError } from "@trpc/client";
import { PublicPage } from "~app/components/public-page";
import type { TRPCError } from "~app/trpc";
import { Spinner } from "~components/spinner";
import { captureSentryError } from "~web/utils/sentry";
import { getLoaderTrpcClient } from "~web/utils/trpc";
const Wrapper = () => (
<PublicPage>
<React.Suspense fallback={<Spinner size="lg" />}>
<Outlet />
</React.Suspense>
</PublicPage>
);
export const Route = createFileRoute("/_public")({
beforeLoad: async ({ context, search }) => {
if (!context.request) {
return;
}
const trpc = getLoaderTrpcClient(context);
try {
await context.queryClient.fetchQuery(trpc.user.get.queryOptions());
} catch (error) {
Eif (error instanceof TRPCClientError) {
const castedError = error as TRPCError;
Eif (castedError.data?.code === "UNAUTHORIZED") {
// It's ok we get an error for the user on public route - bail out
return;
}
}
captureSentryError(error as Error);
throw error;
}
// If we do get an user - we're authorized and we need to get to the app page
// oxlint-disable-next-line typescript/only-throw-error
throw redirect({ to: search.redirect || "/receipts" });
},
component: Wrapper,
});
|