A modern, full-stack authentication system built with Blade React framework, Better Auth, and RONIN edge database. This example demonstrates OAuth authentication (Google & GitHub) with session management and dynamic UI updates.
- π OAuth Authentication - Google & GitHub sign-in
- ποΈ RONIN Edge Database - Serverless SQLite database
- π Session Management - Secure session handling with Better Auth
- β‘ Edge Computing - Instant loading with edge-first architecture
- π¨ Dynamic UI - Content changes based on authentication status
- π Production Ready - Clean, scalable codebase
- Blade - React framework for edge computing
- Better Auth - Modern authentication library
- RONIN - Edge database with instant global replication
- Hono - Fast web framework for the edge
- Tailwind CSS - Utility-first CSS framework
- RONIN Account - Sign up at ronin.co
- Google OAuth App - Google Cloud Console
- GitHub OAuth App - GitHub Developer Settings
git clone https://github.com/MaDsEm88/blade-auth-starter.git
cd blade-auth-starter
bun installCreate a .env file in the root directory:
# RONIN Database
RONIN_TOKEN=your_ronin_app_token
# Better Auth
BETTER_AUTH_SECRET=your_random_secret_key
BETTER_AUTH_URL=http://localhost:3000
# Google OAuth
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
# GitHub OAuth
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secretThe RONIN database schema is automatically managed by Better Auth. No manual setup required!
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
http://localhost:3000/api/auth/callback/google
- Go to GitHub Developer Settings
- Create a new OAuth App
- Set Authorization callback URL:
http://localhost:3000/api/auth/callback/github
bun run devVisit http://localhost:3000 and test the authentication flow!
βββ components/
β βββ auth-status.client.tsx # Dynamic auth status component
βββ lib/
β βββ auth.ts # Better Auth configuration
βββ pages/
β βββ index.tsx # Home page with dynamic content
β βββ auth.tsx # Unified sign-in/sign-up page
βββ router.ts # Hono API routes
βββ schema/
βββ index.ts # RONIN database schema
The authentication is configured in lib/auth.ts:
import { betterAuth } from "better-auth"
import { ronin as roninAdapter } from "@ronin/better-auth"
import ronin from 'ronin';
const client = ronin({
token: process.env["RONIN_TOKEN"],
})
export const auth = betterAuth({
database: roninAdapter(client),
secret: process.env["BETTER_AUTH_SECRET"] as string,
baseURL: "http://localhost:3000",
socialProviders: {
google: {
clientId: process.env["GOOGLE_CLIENT_ID"] as string,
clientSecret: process.env["GOOGLE_CLIENT_SECRET"] as string,
},
github: {
clientId: process.env["GITHUB_CLIENT_ID"] as string,
clientSecret: process.env["GITHUB_CLIENT_SECRET"] as string,
},
},
});The authentication routes are handled in router.ts:
GET /api/auth/session- Get current sessionGET /api/auth/sign-in/google- Google OAuth redirectGET /api/auth/sign-in/github- GitHub OAuth redirectGET /api/auth/sign-out- Sign out userGET /api/auth/callback/*- OAuth callbacks (handled by Better Auth)
- User visits homepage - Shows sign-in options if not authenticated
- OAuth flow - Redirects to Google/GitHub for authentication
- Callback handling - Better Auth processes the OAuth callback
- Session creation - User session stored in RONIN database
- Dynamic UI - Homepage updates to show user information
- Sign out - Clears session and redirects to homepage
Update your .env for production:
BETTER_AUTH_URL=https://your-domain.com
# ... other variables remain the sameUpdate your OAuth app settings:
- Google:
https://your-domain.com/api/auth/callback/google - GitHub:
https://your-domain.com/api/auth/callback/github
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Blade Team for the amazing React framework
- Better Auth for the authentication library
- RONIN for the edge database platform
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If this project helped you, please give it a β on GitHub!