Skip to content

πŸ” Authentication Implementation with Better AuthΒ #1

@halilibrahimcelik

Description

@halilibrahimcelik

πŸ” Authentication Implementation Checklist

Branch: feat/authentication
Project: Finance Tracker
Focus: Better Auth + Google + GitHub + Email/Password


🎯 Branch Scope & Goals

βœ… What This Branch Will Accomplish:

  • Complete authentication system setup
  • User registration and login functionality
  • OAuth integration (Google + GitHub)
  • Route protection for future features
  • Updated navbar with auth state management

❌ What This Branch Will NOT Include:

  • Dashboard implementation (separate branch)
  • Transaction management (separate branch)
  • Database models beyond auth (separate branch)
  • Advanced features like 2FA (future branch)

πŸ“¦ Phase 1: Dependencies & Setup

πŸ”§ Install Required Packages

  • Install Better Auth core:
    pnpm add better-auth @better-auth/nextjs
  • Install OAuth providers:
    pnpm add @auth/google-provider @auth/github-provider
  • Install database adapter:
    pnpm add @better-auth/prisma-adapter prisma @prisma/client

🌍 Environment Configuration

  • Add auth environment variables to .env.local
  • Add .env.local to .gitignore
  • Create .env.example for other developers

πŸ—„οΈ Phase 2: Database Schema (Auth Only)

πŸ“‹ Auth-Related Tables Only

  • Create User model/table
  • Create Session model/table
  • Create Account model/table (OAuth)
  • Run migrations for auth tables
  • Test database connection

βš™οΈ Phase 3: Better Auth Configuration

πŸ”§ Core Auth Setup

  • Create src/lib/auth.ts configuration file
  • Configure email/password provider
  • Configure Google OAuth provider
  • Configure GitHub OAuth provider
  • Set up session management
  • Configure auth callbacks

πŸ› οΈ API Routes Setup

  • Create src/app/api/auth/[...better-auth]/route.ts
  • Test API endpoints locally
  • Verify auth routes work correctly

🎨 Phase 4: Authentication UI Components

πŸ“ Component Structure Setup

  • Create src/components/auth/ directory
  • Create base auth components

πŸ”‘ Sign In Page (/signin)

  • Create src/app/signin/page.tsx
  • Email/password login form with validation
  • Google OAuth button
  • GitHub OAuth button
  • Loading states for all auth methods
  • Error handling and display
  • Redirect to dashboard on success
  • Link to signup page

πŸ“ Sign Up Page (/signup)

  • Create src/app/signup/page.tsx
  • Email/password registration form
  • Form validation
  • Google OAuth button
  • GitHub OAuth button
  • Loading states for all auth methods
  • Error handling and display
  • Redirect to dashboard on success
  • Link to signin page

πŸ›‘οΈ Phase 5: Route Protection & Middleware

🚧 Authentication Middleware

  • Create src/middleware.ts for route protection
  • Protect future dashboard routes (/dashboard/*)
  • Protect future API routes (/api/protected/*)
  • Redirect unauthenticated users to /signin

πŸ”’ Auth Context/Hooks

  • Create src/lib/auth-client.ts for client-side auth
  • Create src/hooks/useAuth.ts custom hook

🧭 Phase 6: Navbar Integration

🎨 Update Navbar Component

  • Add conditional rendering based on auth state
  • Show user profile when authenticated
  • Add logout functionality
  • Update navbar styling for auth states

πŸ”΅ Phase 7: OAuth Provider Setup

πŸ” Google OAuth Configuration

  • Create Google Cloud Console project
  • Enable Google Sign-In API
  • Configure OAuth consent screen
  • Add authorized redirect URIs
  • Get client ID and secret
  • Test Google login flow

⚫ GitHub OAuth Configuration

  • Create GitHub OAuth App in settings
  • Configure application details
  • Add authorization callback URL
  • Get client ID and secret
  • Test GitHub login flow

πŸ§ͺ Phase 8: Testing & Validation

βœ… Manual Testing Checklist

  • Email/password registration works
  • Email/password login works
  • Google OAuth registration works
  • Google OAuth login works
  • GitHub OAuth registration works
  • GitHub OAuth login works
  • Logout works correctly
  • Protected routes redirect to signin
  • Session persists across browser refresh
  • Navbar updates correctly on auth state change

βœ… Success Criteria

🎯 This Branch is Complete When:

  • βœ… Users can register with all 3 methods (email, Google, GitHub)
  • βœ… Users can login with all 3 methods
  • βœ… Protected routes work (redirect to signin)
  • βœ… Navbar shows correct state (authenticated vs not)
  • βœ… Sessions persist across browser refresh
  • βœ… Logout works and clears session
  • βœ… All error cases handled gracefully
  • βœ… OAuth flows work in both development and production

πŸ“Š Branch Metrics

πŸ“… Start Date: October 5, 2025
🎯 Target Completion: 2 weeks
⏱️ Estimated Time: 1-2 weeks
🏷️ Priority: High
πŸ‘€ Assignee: @halilibrahimcelik


πŸ†˜ Resources

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions