This guide will help you set up AuthMaster for local development.
- Node.js 18 or later
- pnpm (recommended) or npm
- Cloudflare account (for deployment)
authmaster/
├── packages/
│ ├── shared/ # Shared types and validation
│ ├── worker-api/ # Cloudflare Workers backend
│ └── web-console/ # React frontend
├── docs/ # Documentation
├── package.json # Root package.json (monorepo)
└── turbo.json # Turborepo configuration
git clone https://github.com/PythonSmall-Q/AuthMaster.git
cd AuthMasternpm installThis will install dependencies for all packages in the monorepo.
Create .dev.vars in packages/worker-api/:
JWT_SECRET=your-secret-key-here
ENCRYPTION_KEY=your-encryption-key-here
FRONTEND_URL=http://localhost:3000
ISSUER=http://localhost:8787
XMOJ_BASE_URL=https://xmoj.techXMOJ_BASE_URL is used by XMOJ account binding verification. During bind,
the backend sends a request with PHPSESSID and verifies by parsing the top-right
profile name from the returned page.
Generate secure random keys:
# Generate JWT secret
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
# Generate encryption key
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"Create .env in packages/web-console/:
VITE_API_URL=http://localhost:8787cd packages/worker-api
# Create local D1 database
npx wrangler d1 create authmaster-db --local
# Run migrations
npx wrangler d1 migrations apply authmaster-db --localOpen two terminal windows:
Terminal 1 - Backend:
cd packages/worker-api
npm run devThe API will be available at http://localhost:8787.
Terminal 2 - Frontend:
cd packages/web-console
npm run devThe frontend will be available at http://localhost:3000.
Build all packages:
npm run buildBuild specific package:
cd packages/shared
npm run buildnpm run testnpm run lintTypeScript compilation happens automatically during build. To check types:
cd packages/worker-api
npx tsc --noEmit
cd packages/web-console
npx tsc --noEmitcd packages/worker-api
npx wrangler d1 execute authmaster-db --local --command "SELECT * FROM users"Create a new migration file in packages/worker-api/migrations/:
-- migrations/0003_add_column.sql
ALTER TABLE users ADD COLUMN last_login TEXT;Apply migration:
npx wrangler d1 migrations apply authmaster-db --localnpx wrangler d1 execute authmaster-db --local --command "DROP TABLE IF EXISTS users; DROP TABLE IF EXISTS applications; DROP TABLE IF EXISTS authorizations; DROP TABLE IF EXISTS oauth_tokens; DROP TABLE IF EXISTS api_usage;"
npx wrangler d1 migrations apply authmaster-db --local- Define types in
packages/shared/src/types.ts - Add validation schema in
packages/shared/src/validation.ts - Create service method in
packages/worker-api/src/services/ - Add route handler in
packages/worker-api/src/routes/index.ts
Example:
// 1. Add type (shared)
export interface MyRequest {
field: string;
}
// 2. Add validation (shared)
export const mySchema = z.object({
field: z.string().min(1),
});
// 3. Add service method (worker-api)
async myMethod(input: MyRequest): Promise<void> {
// Implementation
}
// 4. Add route (worker-api)
router.add('POST', '/api/v1/my-endpoint', async (request, env) => {
const body = await request.json();
const input = mySchema.parse(body);
// Handle request
});Use curl or a tool like Postman:
# Register user
curl -X POST http://localhost:8787/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password123"}'
# Login
curl -X POST http://localhost:8787/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password123"}'
# Create application (requires token)
curl -X POST http://localhost:8787/api/v1/apps/register \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"name":"My App",
"redirect_uris":["http://localhost:3000/callback"],
"scopes":["openid","profile","email"]
}'- Create page component in
packages/web-console/src/pages/ - Add route in
packages/web-console/src/App.tsx
Example:
// 1. Create page component
export function MyPage() {
return (
<div>
<h1>My Page</h1>
</div>
);
}
// 2. Add route
<Route path="/my-page" element={<MyPage />} />Add methods to the API client in packages/web-console/src/api/client.ts:
async myEndpoint(data: any) {
return this.request('/api/v1/my-endpoint', {
method: 'POST',
body: JSON.stringify(data),
});
}The project uses Tailwind CSS. Add utility classes directly to components:
<div className="container mx-auto px-4 py-8">
<h1 className="text-3xl font-bold text-gray-900 mb-4">
Title
</h1>
</div>View worker logs:
cd packages/worker-api
npx wrangler tail --localAdd console.log statements:
console.log('Debug:', { variable });Use browser DevTools:
- Open browser DevTools (F12)
- Check Console for errors
- Use Network tab to inspect API requests
- Use React DevTools extension
If port 8787 or 3000 is in use:
# Find process using port
lsof -i :8787
lsof -i :3000
# Kill process
kill -9 <PID>Reset local database:
cd packages/worker-api
rm -rf .wrangler/state
npx wrangler d1 migrations apply authmaster-db --localEnsure the backend CORS settings allow the frontend origin:
corsHeaders: {
'Access-Control-Allow-Origin': 'http://localhost:3000',
// ...
}Rebuild shared package:
cd packages/shared
npm run build- Use TypeScript for all new code
- Enable strict mode
- Define types for all function parameters and return values
- Use interfaces for object shapes
- Variables/Functions: camelCase
- Constants: UPPER_SNAKE_CASE
- Types/Interfaces: PascalCase
- Files: kebab-case
Add comments for:
- Complex logic
- Non-obvious behavior
- Public APIs
- Security considerations
feature/- New featuresfix/- Bug fixesdocs/- Documentation updatesrefactor/- Code refactoring
Follow conventional commits:
feat: add user profile endpoint
fix: resolve CORS issue on login
docs: update API documentation
refactor: simplify token generation
- Create feature branch
- Make changes
- Write tests
- Update documentation
- Submit PR with description
- Cloudflare Workers Docs
- Cloudflare D1 Docs
- OAuth 2.0 Spec
- OpenID Connect Spec
- React Docs
- Tailwind CSS Docs
- GitHub Issues: Report bugs or request features
- Discussions: Ask questions and share ideas
- Documentation: Check docs for guides and API reference