Advanced authentication playground with PocketBase, featuring WebAuthn/Passkeys, TOTP, and modern web technologies.
-
π Advanced Authentication
- WebAuthn/Passkeys implementation
- TOTP (Time-based One-Time Passwords)
- Traditional email/password authentication
- Multi-factor authentication support
-
π οΈ Modern Tech Stack
- Backend: Go with PocketBase framework (refactored & modular)
- Frontend: SvelteKit 2.x with TypeScript
- Database: SQLite with PocketBase ORM
- Styling: TailwindCSS + DaisyUI
- Build: Embedded frontend with Go embed
- Testing: Comprehensive Go test suite
-
π± User Experience
- Responsive design with mobile-first approach
- SPA routing with fallback support
- Marketing pages and admin dashboard
- Account management and security settings
- Go 1.24.0 or higher
- Node.js 18+ and npm
- Git
git clone <repository-url>
cd pocketbase-experiments
go mod tidyCreate .env file for development:
TOTP_ISSUER="PocketBase Experiments"
PROTO="http"
HOST="localhost"
PORT=":8090"For production, create .env.production with appropriate values.
cd ui
npm install
cd ..go run . serveThe application will be available at http://localhost:8090
# Install/update dependencies
go mod tidy
# Run development server
go run . serve
# Run tests
go test -v
# Run tests with coverage
go test -v -cover
# Update all Go modules
go get -u -t ./...
go mod tidy
# Build and test
go build -o /dev/null . && go test -v# Install dependencies
npm install
# Development server (with hot reload)
npm run dev
# Build for production
npm run build
# Type checking
npm run check
npm run check:watch
# Testing
npm run test
npm run test_run
# Linting and formatting
npm run lint
npm run format
npm run format_check- Passwordless authentication using FIDO2/WebAuthn standard
- Support for Touch ID, Face ID, security keys, and platform authenticators
- Secure credential storage in SQLite database
API Endpoints:
POST /api/pb-experiments/passkey/registerStart- Begin passkey registrationPOST /api/pb-experiments/passkey/registerFinish- Complete passkey registrationPOST /api/pb-experiments/passkey/loginStart- Begin passkey authenticationPOST /api/pb-experiments/passkey/loginFinish- Complete passkey authentication
- QR code generation for authenticator apps
- Support for Google Authenticator, Authy, etc.
- Backup codes and account recovery
API Endpoints:
GET /api/pb-experiments/get-qr- Generate TOTP QR codePOST /api/pb-experiments/totp-login- Verify TOTP passcode
βββ main.go # Main application entry point & routing
βββ config.go # Environment configuration management
βββ auth.go # Authentication service & WebAuthn setup
βββ types.go # Type definitions & interfaces
βββ handlers_totp.go # TOTP-related HTTP handlers
βββ handlers_webauthn.go # WebAuthn-related HTTP handlers
βββ utils.go # Utility functions
βββ models.go # User models & WebAuthn interface
βββ store.go # In-memory session store
βββ core_test.go # Comprehensive test suite
βββ ui/ # SvelteKit frontend
β βββ src/routes/ # Application routes
β βββ src/lib/ # Components and utilities
β βββ embed.go # Frontend embedding
βββ pb_data/ # PocketBase database and storage
- users: User accounts with TOTP secrets
- credentials: WebAuthn credentials
- _mfas: Multi-factor authentication records
π§ Refactored Codebase:
- Modular Design: Separated concerns into dedicated files for better maintainability
- Clean Architecture: Service layer pattern with dependency injection
- Type Safety: Comprehensive type definitions and interfaces
- Error Handling: Standardized error responses and proper error propagation
π§ͺ Testing Suite:
- Unit Tests: Comprehensive test coverage for all core modules
- Edge Cases: Tests for invalid inputs, missing data, and error conditions
- Data Integrity: Serialization/deserialization round-trip testing
- Security: Session ID uniqueness and cryptographic validation
- Configuration: Environment setup and validation testing
Test Coverage:
# Run the full test suite
go test -v
# Key test areas:
β
Configuration management & environment handling
β
Authentication service & WebAuthn initialization
β
Session management with secure session IDs
β
Data structures & JSON serialization
β
Base64 URL encoding for WebAuthn compliance
β
Error handling & edge cases# Generate and build frontend, then compile Go binary
go generate ./...
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o pocketbase-experiments# Ensure .env.production exists with proper configuration
./pocketbase-experiments serveTOTP_ISSUER="Your App Name"
PROTO="https"
HOST="yourdomain.com"
# PORT not needed for production (no :port suffix)Architecture:
- Modular Backend: Refactored Go code with clear separation of concerns
- Service Layer: Authentication service with dependency injection pattern
- Handler Organization: Separate handlers for TOTP and WebAuthn functionality
- Configuration Management: Environment-based config with validation
Technical Details:
- The frontend is automatically built and embedded into the Go binary via
go:generate - WebAuthn sessions are stored in-memory (consider Redis for production scaling)
- PocketBase handles user management, while custom routes handle advanced auth
- Static files are served with gzip compression
- SPA fallback ensures proper routing for client-side navigation
Quality Assurance:
- Comprehensive test suite ensures code reliability
- All core functionality is unit tested
- Error handling is standardized across the application
- Session management includes cryptographic security validation
This project implements multiple layers of security for authentication and data protection. For detailed security information, known vulnerabilities, and best practices, see SECURITY.md.
Key Security Features:
- WebAuthn/FIDO2 passwordless authentication
- TOTP-based multi-factor authentication
- Secure session management with cryptographic tokens
- MIME type validation for file uploads
- Encrypted credential storage
All custom authentication endpoints require proper headers and CORS handling. WebAuthn endpoints use session tokens for state management during the authentication ceremony.
For detailed API usage examples, see the frontend implementation in ui/src/lib/components/.
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
go test -v(backend) andnpm test(frontend) - Run linting:
go vet ./...(backend) andnpm run lint(frontend) - Ensure all tests pass and code follows project patterns
- Submit a pull request
# Backend development
go mod tidy # Install dependencies
go test -v # Run tests
go build -o /dev/null . # Verify build
go run . serve # Start development server
# Frontend development (in ui/ directory)
npm install # Install dependencies
npm run dev # Start dev server with hot reload
npm test # Run frontend tests
npm run lint # Check code styleThis project is licensed under the MIT License. See the LICENSE file for details.