create-authhero 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cloudflare-simple/README.md +109 -10
- package/dist/cloudflare-simple/drizzle.config.ts +8 -0
- package/dist/cloudflare-simple/migrations/0000_init.sql +782 -0
- package/dist/cloudflare-simple/migrations/meta/0000_snapshot.json +5325 -0
- package/dist/cloudflare-simple/migrations/meta/_journal.json +13 -0
- package/dist/cloudflare-simple/seed-helper.js +75 -0
- package/dist/cloudflare-simple/src/app.ts +10 -0
- package/dist/cloudflare-simple/src/db/schema.ts +845 -0
- package/dist/cloudflare-simple/src/index.ts +32 -14
- package/dist/cloudflare-simple/src/seed.ts +64 -0
- package/dist/cloudflare-simple/wrangler.toml +2 -0
- package/dist/create-authhero.js +177 -98
- package/package.json +1 -1
|
@@ -15,25 +15,69 @@ A single-tenant AuthHero authentication server using Cloudflare Workers and D1.
|
|
|
15
15
|
npm install
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
2. Create a D1 database:
|
|
18
|
+
2. Create a D1 database (if not using local mode):
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
21
|
wrangler d1 create authhero-db
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
Update `wrangler.toml` with your database ID from the output above.
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
3. Run database migrations:
|
|
27
|
+
|
|
28
|
+
**For local development:**
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm run migrate
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**For production:**
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm run db:migrate:remote
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
4. Seed the database with an admin user:
|
|
41
|
+
|
|
42
|
+
**For local development:**
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=yourpassword npm run seed:local
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**For production:**
|
|
27
49
|
|
|
28
50
|
```bash
|
|
29
|
-
npm run
|
|
51
|
+
ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=yourpassword npm run seed:remote
|
|
30
52
|
```
|
|
31
53
|
|
|
32
54
|
5. Start the development server:
|
|
55
|
+
|
|
56
|
+
**For local mode (local D1 database):**
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm run dev:local
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**For remote mode (production D1 database):**
|
|
63
|
+
|
|
33
64
|
```bash
|
|
34
|
-
npm run dev
|
|
65
|
+
npm run dev:remote
|
|
35
66
|
```
|
|
36
67
|
|
|
68
|
+
## Available Scripts
|
|
69
|
+
|
|
70
|
+
- `npm run dev:local` - Start development server with local D1 database
|
|
71
|
+
- `npm run dev:remote` - Start development server with remote D1 database
|
|
72
|
+
- `npm run deploy` - Deploy to Cloudflare Workers
|
|
73
|
+
- `npm run migrate` - Run migrations on local database
|
|
74
|
+
- `npm run db:migrate:local` - Run migrations on local database (alias)
|
|
75
|
+
- `npm run db:migrate:remote` - Run migrations on remote database
|
|
76
|
+
- `npm run seed:local` - Seed local database with admin user
|
|
77
|
+
- `npm run seed:remote` - Seed remote database with admin user
|
|
78
|
+
- `npm run db:generate` - Generate new migration from schema changes
|
|
79
|
+
- `npm run db:push` - Push schema changes directly to database (development only)
|
|
80
|
+
|
|
37
81
|
## Deployment
|
|
38
82
|
|
|
39
83
|
1. Deploy to Cloudflare:
|
|
@@ -43,21 +87,76 @@ A single-tenant AuthHero authentication server using Cloudflare Workers and D1.
|
|
|
43
87
|
```
|
|
44
88
|
|
|
45
89
|
2. Run production migrations:
|
|
90
|
+
|
|
46
91
|
```bash
|
|
47
|
-
npm run db:migrate:
|
|
92
|
+
npm run db:migrate:remote
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
3. Seed the production database:
|
|
96
|
+
```bash
|
|
97
|
+
ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=yourpassword npm run seed:remote
|
|
48
98
|
```
|
|
49
99
|
|
|
50
100
|
## Project Structure
|
|
51
101
|
|
|
52
102
|
```
|
|
103
|
+
├── migrations/
|
|
104
|
+
│ └── 0000_init.sql # Initial database schema migration
|
|
53
105
|
├── src/
|
|
54
|
-
│ ├──
|
|
55
|
-
│
|
|
56
|
-
│
|
|
57
|
-
├──
|
|
106
|
+
│ ├── db/
|
|
107
|
+
│ │ └── schema.ts # Drizzle schema (for migration generation)
|
|
108
|
+
│ ├── index.ts # Worker entry point
|
|
109
|
+
│ ├── app.ts # AuthHero app configuration
|
|
110
|
+
│ ├── seed.ts # Database seeding worker
|
|
111
|
+
│ └── types.ts # TypeScript type definitions
|
|
112
|
+
├── drizzle.config.ts # Drizzle Kit configuration
|
|
113
|
+
├── seed-helper.js # Helper script for automated seeding
|
|
114
|
+
├── wrangler.toml # Cloudflare Worker configuration
|
|
58
115
|
└── package.json
|
|
59
116
|
```
|
|
60
117
|
|
|
118
|
+
## Database Migrations
|
|
119
|
+
|
|
120
|
+
This project uses [Drizzle Kit](https://orm.drizzle.team/kit-docs/overview) for generating database migrations from schema changes.
|
|
121
|
+
|
|
122
|
+
### Schema-Driven Migrations
|
|
123
|
+
|
|
124
|
+
The database schema is defined in `src/db/schema.ts` using Drizzle ORM. When you need to make schema changes:
|
|
125
|
+
|
|
126
|
+
1. **Modify the schema** (if customizing beyond the default AuthHero schema)
|
|
127
|
+
|
|
128
|
+
2. **Generate a new migration:**
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm run db:generate
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
This creates a new SQL migration file in the `migrations/` directory.
|
|
135
|
+
|
|
136
|
+
3. **Apply the migration locally:**
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm run db:migrate:local
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
4. **Apply to production:**
|
|
143
|
+
```bash
|
|
144
|
+
npm run db:migrate:remote
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Migration Architecture
|
|
148
|
+
|
|
149
|
+
- **Drizzle ORM**: Defines the database schema in TypeScript
|
|
150
|
+
- **drizzle-kit**: Generates SQL migrations by comparing schema to database state
|
|
151
|
+
- **Kysely**: Used at runtime for executing queries (via @authhero/kysely-adapter)
|
|
152
|
+
|
|
153
|
+
This approach gives you:
|
|
154
|
+
|
|
155
|
+
- Type-safe schema definitions
|
|
156
|
+
- Incremental migrations (only changes are migrated)
|
|
157
|
+
- Full control over migration SQL
|
|
158
|
+
- Compatibility with Cloudflare D1
|
|
159
|
+
|
|
61
160
|
## API Documentation
|
|
62
161
|
|
|
63
162
|
Visit your worker URL with `/docs` to see the Swagger UI documentation.
|