TanStackT
TanStack10mo ago
3 replies
sacred-rose

Code review, need advice on Auth Guarding Setup

stackblitz: https://stackblitz.com/edit/vitejs-vite-aaw7yap9?file=src%2Froutes%2Flogin.tsx

The demo isn't super functional, but it gets the gist across.

I'm trying to find a standardized setup for auth guarding authenticated routes.
This is my file structure:
src/
  main.tsx
  routeTree.gen.ts
  routes/
    - _authenticated/
      - dashboard.tsx
    - __root.tsx
    - _authenticated.tsx
    - index.tsx
    - login.tsx

I have it currently setup with supabase magic links, but that could obviously be abstracted out. I'm more concerned about the router logic. Is there anything that jumps out or seems odd, or could be improved? I'm looking to do this across multiple apps I'm building. It feels kinda bad, but I'm not sure what could be better.
StackBlitzJakeHadley
Next generation frontend tooling. It's fast!
Vitejs - Vite (forked) - StackBlitz
Was this page helpful?