Skip to content

Refactor of the basic auth example code to use amplify authenticator component and backend data

License

Notifications You must be signed in to change notification settings

jayarerita/tanstack-start-basic-auth-amplify

Repository files navigation

πŸš€ TanStack Start + AWS Amplify Gen 2 Template

CI License: MIT TypeScript AWS Amplify

A modern, production-ready template for building full-stack React applications with TanStack Start and AWS Amplify Gen 2.

✨ Features

πŸ” Authentication

  • AWS Cognito User Pools with email/password
  • Amplify UI components for sign-in/sign-up
  • Email confirmation and password reset
  • Protected routes with automatic redirects
  • Session management with JWT tokens

πŸ—„οΈ Backend

  • AWS Amplify Gen 2 GraphQL API & Cognito Auth

🎨 Frontend

  • TanStack Start for full-stack React
  • TanStack Router for type-safe routing
  • TypeScript throughout the entire stack
  • Tailwind CSS for styling

πŸš€ Quick Start

1. Use This Template

Click the "Use this template" button above or:

gh repo create my-awesome-app --template jayarerita/tanstack-start-amplify-template
cd my-awesome-app

2. Install Dependencies

npm install

3. Set Up AWS Backend

npm run amplify:sandbox

This will:

  • Deploy your backend to AWS
  • Generate amplify_outputs.json configuration
  • Set up Cognito User Pool and AppSync API

4. Start Development

npm run dev

5. Open Your App

Navigate to http://localhost:3000 and start building! πŸŽ‰

πŸ“ Project Structure

β”œβ”€β”€ amplify/                    # AWS Amplify backend
β”‚   β”œβ”€β”€ auth/resource.ts       # Cognito configuration
β”‚   β”œβ”€β”€ data/resource.ts       # GraphQL schema & DynamoDB
β”‚   └── backend.ts             # Main backend setup
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/            # React components
β”‚   β”‚   β”œβ”€β”€ AuthenticatorWrapper.tsx
β”‚   β”‚   └── Login.tsx
β”‚   β”œβ”€β”€ hooks/                 # Custom React hooks
β”‚   β”‚   └── useAuth.ts
β”‚   β”œβ”€β”€ lib/                   # Utilities & configuration
β”‚   β”‚   β”œβ”€β”€ amplify.ts
β”‚   β”‚   β”œβ”€β”€ data.ts
β”‚   β”‚   └── amplify-ui-theme.ts
β”‚   β”œβ”€β”€ routes/                # TanStack Router routes
β”‚   β”‚   β”œβ”€β”€ __root.tsx         # Root layout
β”‚   β”‚   β”œβ”€β”€ index.tsx          # Home page
β”‚   β”‚   β”œβ”€β”€ login.tsx          # Authentication
β”‚   β”‚   └── _authed/           # Protected routes
β”‚   └── styles/
β”‚       └── app.css            # Global styles
└── README.md

πŸ› οΈ Available Scripts

Command Description
npm run dev Start development server
npm run build Build for production
npm run start Start production server
npm run amplify:sandbox Deploy backend to sandbox
npm run amplify:deploy Deploy backend to production

🎨 Customization

Authentication UI

Customize the authentication experience in src/components/AuthenticatorWrapper.tsx:

<Authenticator
  signUpAttributes={['email']}
  socialProviders={['google', 'facebook']} // Add social providers
  components={{
    Header() {
      return <YourCustomHeader />
    }
  }}
>

Database Schema

Add new data models in amplify/data/resource.ts:

const schema = a.schema({
  Post: a.model({
    title: a.string().required(),
    content: a.string().required(),
    // Add your fields here
  }).authorization((allow) => [
    allow.authenticated()
  ])
})

Styling

  • Global styles: src/styles/app.css
  • Amplify UI theme: src/lib/amplify-ui-theme.ts
  • Tailwind configuration: tailwind.config.mjs

πŸš€ Deployment

Backend

# Development
npm run amplify:sandbox

# Production
npm run amplify:deploy

Frontend

Deploy to any static hosting service:

  • AWS Amplify Hosting (recommended)
  • Vercel
  • Netlify
  • AWS S3 + CloudFront

πŸ“š Documentation

πŸ”— Learn More

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

⭐ Show Your Support

If this template helped you, please give it a star! ⭐


Built with ❀️ using TanStack Start and AWS Amplify

About

Refactor of the basic auth example code to use amplify authenticator component and backend data

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors