A complete GitHub OAuth implementation template that demonstrates how to build OAuth authentication without database sessions, using secure HTTP-only cookies to store credentials.
Create a GitHub OAuth App:
https://your-val-name.web.val.run
https://your-val-name.web.val.run/auth/callback
Set Environment Variables in Val Town:
GITHUB_CLIENT_ID
: Your GitHub OAuth app's client IDGITHUB_CLIENT_SECRET
: Your GitHub OAuth app's client secretDeploy:
backend/index.ts
https://your-val-name.web.val.run
āāā backend/
ā āāā index.ts # Main Hono app with OAuth routes
ā āāā github.ts # GitHub API client
āāā frontend/
ā āāā index.html # Main HTML template
ā āāā app.tsx # React app component
ā āāā style.css # Styling
āāā shared/
ā āāā types.ts # Shared TypeScript types
āāā README.md
Authentication Flow:
API Requests:
Security:
GET /
- Main application pageGET /auth/login
- Initiate GitHub OAuth flowGET /auth/callback
- Handle OAuth callbackGET /auth/logout
- Clear authentication cookiesGET /api/user
- Get authenticated user profileGET /api/repos
- Get user's repositoriesGITHUB_CLIENT_ID
- GitHub OAuth app client ID (required)GITHUB_CLIENT_SECRET
- GitHub OAuth app client secret (required)