Skip to content

G4brym/authentication-using-d1-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d8b28bc · Nov 12, 2024

History

12 Commits
Jun 23, 2023
Jun 23, 2023
Nov 12, 2024
Jun 23, 2023
May 28, 2023
Sep 4, 2024
Nov 12, 2024
Nov 12, 2024
Nov 12, 2024
Sep 4, 2024

Repository files navigation

Example code for implementing Register and Login in Cloudflare Workers using D1

This is the example code for the article Implementing Register and Login in Cloudflare Workers with D1 that you can read here.

Technologies used:

Getting started with this project

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/

Images

Swagger interface Swagger interface

Unauthenticated Unauthenticated

Authentication Authentication

Endpoint results Endpoint results