Skip to content

mwolf1989/tanstack-starter

Repository files navigation

A minimal starter template for 🏝️ TanStack Start with Supabase authentication, forked from dotnize/tanstarter.

Getting Started

  1. Clone this repository:

    git clone https://github.com/mwolf1989/tanstack-starter.git
  2. Install dependencies:

    pnpm install # npm install
  3. Create a .env file based on .env.example and add your Supabase credentials:

    VITE_SUPABASE_URL=your_supabase_project_url
    VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
    SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
  4. Run the development server:

    pnpm dev # npm run dev

    The development server should be now running at http://localhost:3000.

Database Seeding

This template includes a database seeding system using Supabase. To seed the database with sample data:

  1. Link your project (if not already linked):

    pnpm supabase link --project-ref your-project-ref
  2. Run the seed command:

    pnpm db:seed

This will reset your database and apply the seed data defined in supabase/seed.sql. The seed file includes sample todos that you can use as a starting point.

Note: The seed data uses a placeholder user ID. You'll need to replace the user IDs in supabase/seed.sql with actual user IDs from your Supabase auth system.

Authentication with Supabase

This template uses Supabase for authentication with server-side rendering (SSR) support. Key features:

  • Server-side authentication using @supabase/ssr
  • Proper cookie handling for authentication tokens
  • Protected routes with automatic redirection
  • Email/Password and OAuth authentication support
  • Type-safe authentication functions

Authentication Flow

  1. Sign In: Server-side authentication with proper cookie management

    const signInFn = createServerFn()
      .validator((d) => d as SignInCredentials)
      .handler(async ({ data }) => {
        const supabase = getSupabaseServerClient();
        const { error } = await supabase.auth.signInWithPassword(data);
        // Cookies are automatically handled
        return error ? { error: true } : { success: true };
      });
  2. Protected Routes: Automatic authentication checks and redirects

    export const Route = createFileRoute("/dashboard")({
      loader: async ({ context }) => {
        const result = await context.queryClient.fetchQuery({
          queryKey: ["dashboard-auth"],
          queryFn: () => checkAuth(),
        });
        if (!result.authenticated) {
          throw redirect({ to: "/signin" });
        }
        return { user: result.user };
      },
    });

Model Context Protocol (MCP)

This template includes support for the Model Context Protocol (MCP), which allows AI tools to interact with your Supabase database using natural language commands. To set up MCP:

  1. Create a .cursor directory in your project root if it doesn't exist
  2. Create a .cursor/mcp.json file with the following configuration:
    {
      "mcpServers": {
        "supabase": {
          "command": "npx",
          "args": ["-y", "@modelcontextprotocol/server-postgres", "<connection-string>"]
        }
      }
    }
  3. Replace <connection-string> with your Supabase database connection string from your project's Connection settings

Once configured, you can use AI tools to:

  • Query your database using natural language
  • Create and modify tables
  • Perform SQL operations
  • Get insights about your data structure

For more information, read the Supabase MCP Article.

Issue watchlist

Scripts

These scripts in package.json use pnpm by default, but you can modify them to use your preferred package manager.

  • ui - The shadcn/ui CLI. (e.g. pnpm ui add button to add the button component)
  • format and lint - Run Prettier and ESLint.

Building for production

Read the hosting docs for information on how to deploy your TanStack Start app.

Acknowledgements

About

TanStack Start Supabase and Shadcn Starter

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published