Advertisement
MrB4RC0D3

App Route

Apr 15th, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 0.91 KB | Source Code | 0 0
  1. import { createFileRoute, redirect } from "@tanstack/react-router";
  2. import { z } from "zod";
  3. import WorkshopWizardApp from "../../pages/app";
  4.  
  5. const appSearchSchema = z.object({
  6.     view: z.enum(["dashboard", "application", "other"]).catch("dashboard"),
  7. });
  8.  
  9. export type AppSearch = z.infer<typeof appSearchSchema>;
  10.  
  11. export const Route: any = createFileRoute("/app/")({
  12.     beforeLoad: ({ context, location }) => {
  13.         console.log("Context Auth " + context.auth.isAuthenticated);
  14.         if (context.auth.isAuthenticated === null || context.auth.isAuthenticated === false) {
  15.             throw redirect({
  16.                 to: "/auth",
  17.                 search: {
  18.                     redirect: location.href,
  19.                     form: "signin",
  20.                 },
  21.             });
  22.         }
  23.     },
  24.  
  25.     validateSearch: (search) => appSearchSchema.parse(search),
  26.     component: () => <WorkshopWizardApp />,
  27. });
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement