This is the example code for the article Implementing Register and Login in Cloudflare Workers with D1
that you can read here.
Technologies used:
- hono for routing
- chanfana for OpenAPI generation and validation
- workers-qb for querying D1
Install the dependencies
npm install
Create a new D1 database
wrangler d1 create <db-name> --experimental-backend
Copy the database_id
and place it in the wrangler.toml
file
[[d1_databases]]
binding = "DB"
database_name = "<your-db-name>"
database_id = "<your-db-id>"
Apply initial migrations, that include the users
and users_sessions
tables
# Remote development
wrangler d1 migrations apply DB
# Local development
wrangler d1 migrations apply DB --local
Start the project
npm run serve
Now open your browser at http://localhost:8787/