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