Open History to see the last commit
1import { createFileRoute, redirect, useNavigate } from "@tanstack/react-router";
2
3import {
4 HostedPairingRouteSurface,
5 PairingPendingSurface,
6 PairingRouteSurface,
7} from "../components/auth/PairingRouteSurface";
8
9export const Route = createFileRoute("/pair")({
10 beforeLoad: async ({ context }) => {
11 const { authGateState } = context;
12 if (authGateState.status === "hosted-pairing") {
13 return {
14 authGateState,
15 };
16 }
17
18 if (authGateState.status === "authenticated" || authGateState.status === "hosted-static") {
19 throw redirect({ to: "/", replace: true });
20 }
21 return {
22 authGateState,
23 };
24 },
25 component: PairRouteView,
26 pendingComponent: PairRoutePendingView,
27});
28
29function PairRouteView() {
30 const { authGateState } = Route.useRouteContext();
31 const navigate = useNavigate();
32
33 if (!authGateState) {
34 return null;
35 }
36
37 if (authGateState.status === "hosted-pairing") {
38 return <HostedPairingRouteSurface />;
39 }
40
41 return (
42 <PairingRouteSurface
43 auth={authGateState.auth}
44 onAuthenticated={() => {
45 void navigate({ to: "/", replace: true });
46 }}
47 {...(authGateState.errorMessage ? { initialErrorMessage: authGateState.errorMessage } : {})}
48 />
49 );
50}
51
52function PairRoutePendingView() {
53 return <PairingPendingSurface />;
54}