@korajs/cli 0.5.0 → 0.6.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/bin.cjs +76 -7
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +3 -3
- package/dist/{chunk-PSRM56B7.js → chunk-EEZNRI5W.js} +51 -6
- package/dist/chunk-EEZNRI5W.js.map +1 -0
- package/dist/{chunk-SOTZIWIF.js → chunk-Q2FBCOQD.js} +2 -2
- package/dist/{chunk-3WNFM3QB.js → chunk-VLTPEATY.js} +70 -4
- package/dist/chunk-VLTPEATY.js.map +1 -0
- package/dist/create.cjs +76 -7
- package/dist/create.cjs.map +1 -1
- package/dist/create.js +2 -2
- package/dist/index.cjs +65 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/package.json +6 -6
- package/templates/svelte-basic/.env.example +3 -0
- package/templates/svelte-basic/README.md.hbs +62 -0
- package/templates/svelte-basic/index.html.hbs +12 -0
- package/templates/svelte-basic/kora.config.ts +12 -0
- package/templates/svelte-basic/package.json.hbs +27 -0
- package/templates/svelte-basic/src/App.svelte +131 -0
- package/templates/svelte-basic/src/Root.svelte +14 -0
- package/templates/svelte-basic/src/index.css +287 -0
- package/templates/svelte-basic/src/kora-worker.ts +9 -0
- package/templates/svelte-basic/src/main.ts +16 -0
- package/templates/svelte-basic/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/svelte-basic/src/modules/todos/todo.queries.ts +5 -0
- package/templates/svelte-basic/src/modules/todos/todo.schema.ts +10 -0
- package/templates/svelte-basic/src/modules/todos/useTodos.ts +25 -0
- package/templates/svelte-basic/src/schema.ts +9 -0
- package/templates/svelte-basic/src/vite-env.d.ts +12 -0
- package/templates/svelte-basic/svelte.config.js +5 -0
- package/templates/svelte-basic/tsconfig.json.hbs +14 -0
- package/templates/svelte-basic/vite.config.ts +52 -0
- package/templates/svelte-sync/.env.example +25 -0
- package/templates/svelte-sync/README.md.hbs +105 -0
- package/templates/svelte-sync/index.html.hbs +12 -0
- package/templates/svelte-sync/kora.config.ts +17 -0
- package/templates/svelte-sync/package.json.hbs +43 -0
- package/templates/svelte-sync/server.ts +90 -0
- package/templates/svelte-sync/src/App.svelte +154 -0
- package/templates/svelte-sync/src/Root.svelte +22 -0
- package/templates/svelte-sync/src/auth.ts +25 -0
- package/templates/svelte-sync/src/index.css +339 -0
- package/templates/svelte-sync/src/kora-worker.ts +9 -0
- package/templates/svelte-sync/src/main.ts +32 -0
- package/templates/svelte-sync/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/svelte-sync/src/modules/todos/todo.queries.ts +5 -0
- package/templates/svelte-sync/src/modules/todos/todo.schema.ts +10 -0
- package/templates/svelte-sync/src/modules/todos/useTodos.ts +25 -0
- package/templates/svelte-sync/src/schema.ts +9 -0
- package/templates/svelte-sync/src/vite-env.d.ts +21 -0
- package/templates/svelte-sync/svelte.config.js +5 -0
- package/templates/svelte-sync/tsconfig.json.hbs +14 -0
- package/templates/svelte-sync/vite.config.ts +79 -0
- package/templates/svelte-tailwind/README.md.hbs +62 -0
- package/templates/svelte-tailwind/index.html.hbs +12 -0
- package/templates/svelte-tailwind/kora.config.ts +12 -0
- package/templates/svelte-tailwind/package.json.hbs +30 -0
- package/templates/svelte-tailwind/src/App.svelte +79 -0
- package/templates/svelte-tailwind/src/Root.svelte +14 -0
- package/templates/svelte-tailwind/src/index.css +7 -0
- package/templates/svelte-tailwind/src/kora-worker.ts +9 -0
- package/templates/svelte-tailwind/src/main.ts +16 -0
- package/templates/svelte-tailwind/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/svelte-tailwind/src/modules/todos/todo.queries.ts +5 -0
- package/templates/svelte-tailwind/src/modules/todos/todo.schema.ts +10 -0
- package/templates/svelte-tailwind/src/modules/todos/useTodos.ts +25 -0
- package/templates/svelte-tailwind/src/schema.ts +9 -0
- package/templates/svelte-tailwind/src/vite-env.d.ts +12 -0
- package/templates/svelte-tailwind/svelte.config.js +5 -0
- package/templates/svelte-tailwind/tsconfig.json.hbs +14 -0
- package/templates/svelte-tailwind/vite.config.ts +53 -0
- package/templates/svelte-tailwind-sync/.env.example +25 -0
- package/templates/svelte-tailwind-sync/README.md.hbs +105 -0
- package/templates/svelte-tailwind-sync/index.html.hbs +12 -0
- package/templates/svelte-tailwind-sync/kora.config.ts +17 -0
- package/templates/svelte-tailwind-sync/package.json.hbs +46 -0
- package/templates/svelte-tailwind-sync/server.ts +90 -0
- package/templates/svelte-tailwind-sync/src/App.svelte +196 -0
- package/templates/svelte-tailwind-sync/src/Root.svelte +26 -0
- package/templates/svelte-tailwind-sync/src/auth.ts +25 -0
- package/templates/svelte-tailwind-sync/src/index.css +7 -0
- package/templates/svelte-tailwind-sync/src/kora-worker.ts +9 -0
- package/templates/svelte-tailwind-sync/src/main.ts +32 -0
- package/templates/svelte-tailwind-sync/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/svelte-tailwind-sync/src/modules/todos/todo.queries.ts +5 -0
- package/templates/svelte-tailwind-sync/src/modules/todos/todo.schema.ts +10 -0
- package/templates/svelte-tailwind-sync/src/modules/todos/useTodos.ts +25 -0
- package/templates/svelte-tailwind-sync/src/schema.ts +9 -0
- package/templates/svelte-tailwind-sync/src/vite-env.d.ts +21 -0
- package/templates/svelte-tailwind-sync/svelte.config.js +5 -0
- package/templates/svelte-tailwind-sync/tsconfig.json.hbs +14 -0
- package/templates/svelte-tailwind-sync/vite.config.ts +80 -0
- package/templates/vue-basic/README.md.hbs +62 -0
- package/templates/vue-basic/index.html.hbs +12 -0
- package/templates/vue-basic/kora.config.ts +12 -0
- package/templates/vue-basic/package.json.hbs +26 -0
- package/templates/vue-basic/src/App.vue +117 -0
- package/templates/vue-basic/src/index.css +287 -0
- package/templates/vue-basic/src/kora-worker.ts +9 -0
- package/templates/vue-basic/src/main.ts +20 -0
- package/templates/vue-basic/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/vue-basic/src/modules/todos/todo.queries.ts +5 -0
- package/templates/vue-basic/src/modules/todos/todo.schema.ts +10 -0
- package/templates/vue-basic/src/modules/todos/useTodos.ts +32 -0
- package/templates/vue-basic/src/schema.ts +9 -0
- package/templates/vue-basic/src/vite-env.d.ts +17 -0
- package/templates/vue-basic/tsconfig.json.hbs +15 -0
- package/templates/vue-basic/vite.config.ts +69 -0
- package/templates/vue-sync/.env.example +25 -0
- package/templates/vue-sync/README.md.hbs +105 -0
- package/templates/vue-sync/index.html.hbs +12 -0
- package/templates/vue-sync/kora.config.ts +17 -0
- package/templates/vue-sync/package.json.hbs +42 -0
- package/templates/vue-sync/server.ts +90 -0
- package/templates/vue-sync/src/App.vue +135 -0
- package/templates/vue-sync/src/auth.ts +25 -0
- package/templates/vue-sync/src/index.css +339 -0
- package/templates/vue-sync/src/kora-worker.ts +9 -0
- package/templates/vue-sync/src/main.ts +43 -0
- package/templates/vue-sync/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/vue-sync/src/modules/todos/todo.queries.ts +5 -0
- package/templates/vue-sync/src/modules/todos/todo.schema.ts +10 -0
- package/templates/vue-sync/src/modules/todos/useTodos.ts +32 -0
- package/templates/vue-sync/src/schema.ts +9 -0
- package/templates/vue-sync/src/vite-env.d.ts +26 -0
- package/templates/vue-sync/tsconfig.json.hbs +15 -0
- package/templates/vue-sync/vite.config.ts +79 -0
- package/templates/vue-tailwind/README.md.hbs +62 -0
- package/templates/vue-tailwind/index.html.hbs +12 -0
- package/templates/vue-tailwind/kora.config.ts +12 -0
- package/templates/vue-tailwind/package.json.hbs +29 -0
- package/templates/vue-tailwind/src/App.vue +142 -0
- package/templates/vue-tailwind/src/index.css +7 -0
- package/templates/vue-tailwind/src/kora-worker.ts +9 -0
- package/templates/vue-tailwind/src/main.ts +31 -0
- package/templates/vue-tailwind/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/vue-tailwind/src/modules/todos/todo.queries.ts +5 -0
- package/templates/vue-tailwind/src/modules/todos/todo.schema.ts +10 -0
- package/templates/vue-tailwind/src/modules/todos/useTodos.ts +32 -0
- package/templates/vue-tailwind/src/schema.ts +9 -0
- package/templates/vue-tailwind/src/vite-env.d.ts +17 -0
- package/templates/vue-tailwind/tsconfig.json.hbs +15 -0
- package/templates/vue-tailwind/vite.config.ts +70 -0
- package/templates/vue-tailwind-sync/.env.example +25 -0
- package/templates/vue-tailwind-sync/README.md.hbs +105 -0
- package/templates/vue-tailwind-sync/index.html.hbs +12 -0
- package/templates/vue-tailwind-sync/kora.config.ts +17 -0
- package/templates/vue-tailwind-sync/package.json.hbs +45 -0
- package/templates/vue-tailwind-sync/server.ts +90 -0
- package/templates/vue-tailwind-sync/src/App.vue +245 -0
- package/templates/vue-tailwind-sync/src/auth.ts +25 -0
- package/templates/vue-tailwind-sync/src/index.css +7 -0
- package/templates/vue-tailwind-sync/src/kora-worker.ts +9 -0
- package/templates/vue-tailwind-sync/src/main.ts +56 -0
- package/templates/vue-tailwind-sync/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/vue-tailwind-sync/src/modules/todos/todo.queries.ts +5 -0
- package/templates/vue-tailwind-sync/src/modules/todos/todo.schema.ts +10 -0
- package/templates/vue-tailwind-sync/src/modules/todos/useTodos.ts +32 -0
- package/templates/vue-tailwind-sync/src/schema.ts +9 -0
- package/templates/vue-tailwind-sync/src/vite-env.d.ts +26 -0
- package/templates/vue-tailwind-sync/tsconfig.json.hbs +15 -0
- package/templates/vue-tailwind-sync/vite.config.ts +80 -0
- package/dist/chunk-3WNFM3QB.js.map +0 -1
- package/dist/chunk-PSRM56B7.js.map +0 -1
- /package/dist/{chunk-SOTZIWIF.js.map → chunk-Q2FBCOQD.js.map} +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
An offline-first application built with [Kora.js](https://ehoneahobed.github.io/kora/).
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This starts both the Vite dev server and the Kora sync server.
|
|
12
|
+
|
|
13
|
+
- **App**: http://localhost:5173
|
|
14
|
+
- **Sync server**: ws://localhost:3001
|
|
15
|
+
|
|
16
|
+
## Project Structure
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
src/
|
|
20
|
+
schema.ts # Schema entry point
|
|
21
|
+
auth.ts # Auth client and OAuth callback handling
|
|
22
|
+
main.tsx # App initialization and Kora setup
|
|
23
|
+
App.tsx # Main application component
|
|
24
|
+
modules/
|
|
25
|
+
todos/
|
|
26
|
+
todo.schema.ts # Todo collection definition
|
|
27
|
+
todo.queries.ts # Reusable todo query builders
|
|
28
|
+
todo.mutations.ts # Todo mutation helpers
|
|
29
|
+
useTodos.ts # React hook connecting todos to the UI
|
|
30
|
+
kora-worker.ts # SQLite WASM web worker
|
|
31
|
+
index.css # Styles
|
|
32
|
+
server.ts # Kora sync server
|
|
33
|
+
kora.config.ts # Kora configuration
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
In a feature module, `schema` defines data shape, `queries` contain reads only, `mutations` contain
|
|
37
|
+
writes, and `useTodos.ts` is the React binding that exposes todo data and actions to components.
|
|
38
|
+
|
|
39
|
+
## Environment Variables
|
|
40
|
+
|
|
41
|
+
| Variable | Default | Description |
|
|
42
|
+
|----------|---------|-------------|
|
|
43
|
+
| `VITE_SYNC_URL` | `ws://localhost:3001` | WebSocket URL for the sync server |
|
|
44
|
+
| `VITE_AUTH_URL` | current origin | HTTP URL for `/auth/*` routes |
|
|
45
|
+
| `PORT` | `3001` | Sync server port |
|
|
46
|
+
| `KORA_SERVER_DB` | `./kora-server.db` | SQLite file used by the sync server when `DATABASE_URL` is empty |
|
|
47
|
+
| `KORA_AUTH_DB` | `./kora-auth.db` | SQLite file used by OAuth state and linked identities when `DATABASE_URL` is empty |
|
|
48
|
+
| `DATABASE_URL` | (none) | PostgreSQL connection string for production sync server deployments |
|
|
49
|
+
| `KORA_SYNC_PATH` | `/kora-sync` | WebSocket path exposed by the sync server |
|
|
50
|
+
| `KORA_AUTH_SECRET` | (none) | Enables built-in `/auth/*` routes and authenticated sync when set |
|
|
51
|
+
| `KORA_GOOGLE_CLIENT_ID` | (none) | Enables Google OAuth when set with `KORA_GOOGLE_REDIRECT_URI` |
|
|
52
|
+
| `KORA_GOOGLE_CLIENT_SECRET` | (none) | Google OAuth client secret for confidential web clients |
|
|
53
|
+
| `KORA_GOOGLE_REDIRECT_URI` | (none) | OAuth callback URL, usually your app URL that handles `code` and `state` |
|
|
54
|
+
| `KORA_OAUTH_PKCE` | `true` when no client secret | Enables PKCE for public desktop/mobile OAuth clients |
|
|
55
|
+
| `KORA_ADMIN_TOKEN` | (none) | Protects `/__kora`, `/__kora/status`, and `/__kora/events` |
|
|
56
|
+
| `KORA_METRICS_TOKEN` | (none) | Protects `/__kora/metrics` |
|
|
57
|
+
| `KORA_BACKUP_TOKEN` | (none) | Protects server backup and restore endpoints |
|
|
58
|
+
|
|
59
|
+
## Authentication
|
|
60
|
+
|
|
61
|
+
Set `KORA_AUTH_SECRET` to enable built-in auth on the sync server. Generate a secret with:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The template already creates `src/auth.ts`, wraps the app in `AuthProvider`, and wires sync with `createKoraAuthSync({ authClient, schema })`. To enable Google OAuth, set:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
KORA_AUTH_SECRET=...
|
|
71
|
+
KORA_GOOGLE_CLIENT_ID=...
|
|
72
|
+
KORA_GOOGLE_CLIENT_SECRET=...
|
|
73
|
+
KORA_GOOGLE_REDIRECT_URI=http://localhost:5173
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Use `authClient.signInWithOAuth('google')` for web redirect sign-in, or `authClient.getOAuthAuthorizationUrl('google')` plus `authClient.completeOAuthSignIn('google', { code, state })` for custom handoff flows. See the [Authentication Guide](https://ehoneahobed.github.io/kora/guide/authentication).
|
|
77
|
+
|
|
78
|
+
## Scripts
|
|
79
|
+
|
|
80
|
+
| Script | Description |
|
|
81
|
+
|--------|-------------|
|
|
82
|
+
| `npm run dev` | Start dev server + sync server |
|
|
83
|
+
| `npm run dev:server` | Start sync server only |
|
|
84
|
+
| `npm run build` | Build for production |
|
|
85
|
+
| `npm run preview` | Preview production build |
|
|
86
|
+
|
|
87
|
+
## Deployment
|
|
88
|
+
|
|
89
|
+
The client and sync server must be deployed separately:
|
|
90
|
+
|
|
91
|
+
- **Client**: Any static host (Vercel, Netlify, Cloudflare Pages)
|
|
92
|
+
- **Sync server**: Any Node.js host with WebSocket support (Railway, Render, Fly.io)
|
|
93
|
+
|
|
94
|
+
Set `VITE_SYNC_URL` to your deployed sync server URL when building:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
VITE_SYNC_URL=wss://your-server.example.com npm run build
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Learn More
|
|
101
|
+
|
|
102
|
+
- [Documentation](https://ehoneahobed.github.io/kora/)
|
|
103
|
+
- [Storage Configuration](https://ehoneahobed.github.io/kora/guide/storage-configuration)
|
|
104
|
+
- [Sync Configuration](https://ehoneahobed.github.io/kora/guide/sync-configuration)
|
|
105
|
+
- [Deployment Guide](https://ehoneahobed.github.io/kora/guide/deployment)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>{{projectName}}</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="/src/main.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from 'korajs/config'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
schema: './src/schema.ts',
|
|
5
|
+
dev: {
|
|
6
|
+
port: 5173,
|
|
7
|
+
sync: {
|
|
8
|
+
enabled: true,
|
|
9
|
+
port: 3001,
|
|
10
|
+
store: 'sqlite',
|
|
11
|
+
},
|
|
12
|
+
watch: {
|
|
13
|
+
enabled: true,
|
|
14
|
+
debounceMs: 300,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{projectName}}",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "kora dev",
|
|
8
|
+
"dev:server": "tsx server.ts",
|
|
9
|
+
"build": "vue-tsc --noEmit && vite build",
|
|
10
|
+
"start": "node --import tsx server.ts",
|
|
11
|
+
"preview": "vite preview"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"korajs": "{{koraVersion}}",
|
|
15
|
+
"@korajs/auth": "{{koraVersion}}",
|
|
16
|
+
"@korajs/vue": "{{koraVersion}}",
|
|
17
|
+
"@korajs/store": "{{koraVersion}}",
|
|
18
|
+
"@sqlite.org/sqlite-wasm": ">=3.51.0-build1",
|
|
19
|
+
"vue": "^3.5.0",
|
|
20
|
+
"ws": "^8.18.0",
|
|
21
|
+
"yjs": "^13.6.30"
|
|
22
|
+
},
|
|
23
|
+
"pnpm": {
|
|
24
|
+
"onlyBuiltDependencies": [
|
|
25
|
+
"better-sqlite3",
|
|
26
|
+
"esbuild",
|
|
27
|
+
"protobufjs"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@korajs/cli": "{{koraVersion}}",
|
|
32
|
+
"@korajs/server": "{{koraVersion}}",
|
|
33
|
+
"@types/ws": "^8.5.0",
|
|
34
|
+
"@vitejs/plugin-vue": "^5.2.0",
|
|
35
|
+
"better-sqlite3": "^12.9.0",
|
|
36
|
+
"postgres": "^3.4.0",
|
|
37
|
+
"tsx": "^4.19.0",
|
|
38
|
+
"typescript": "^5.7.0",
|
|
39
|
+
"vite": "^6.0.0",
|
|
40
|
+
"vue-tsc": "^2.2.0"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CreateKoraAuthServerOptions,
|
|
3
|
+
createKoraAuthServer,
|
|
4
|
+
createPostgresOAuthStores,
|
|
5
|
+
createSqliteOAuthStores,
|
|
6
|
+
googleProvider,
|
|
7
|
+
} from '@korajs/auth/server'
|
|
8
|
+
import {
|
|
9
|
+
createPostgresServerStore,
|
|
10
|
+
createProductionServer,
|
|
11
|
+
createSqliteServerStore,
|
|
12
|
+
} from '@korajs/server'
|
|
13
|
+
import schema from './src/schema'
|
|
14
|
+
|
|
15
|
+
async function createStore() {
|
|
16
|
+
if (process.env.DATABASE_URL) {
|
|
17
|
+
return createPostgresServerStore({
|
|
18
|
+
connectionString: process.env.DATABASE_URL,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return createSqliteServerStore({
|
|
23
|
+
filename: process.env.KORA_SERVER_DB || './kora-server.db',
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function start() {
|
|
28
|
+
const store = await createStore()
|
|
29
|
+
await store.setSchema(schema)
|
|
30
|
+
|
|
31
|
+
const syncPath = process.env.KORA_SYNC_PATH || '/kora-sync'
|
|
32
|
+
const auth = await createAuth()
|
|
33
|
+
const server = createProductionServer({
|
|
34
|
+
store,
|
|
35
|
+
port: Number(process.env.PORT) || 3001,
|
|
36
|
+
staticDir: './dist',
|
|
37
|
+
syncPath,
|
|
38
|
+
httpRoutes: auth ? [{ path: '/auth', handle: auth.handleRequest }] : undefined,
|
|
39
|
+
syncOptions: auth ? { auth: auth.auth } : undefined,
|
|
40
|
+
operationalAuth: {
|
|
41
|
+
adminToken: process.env.KORA_ADMIN_TOKEN,
|
|
42
|
+
metricsToken: process.env.KORA_METRICS_TOKEN,
|
|
43
|
+
backupToken: process.env.KORA_BACKUP_TOKEN,
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const url = await server.start()
|
|
48
|
+
console.log(`Kora app running at ${url}`)
|
|
49
|
+
console.log(` Sync endpoint: ${url.replace('http', 'ws')}${syncPath}`)
|
|
50
|
+
if (auth) console.log(` Auth endpoint: ${url}/auth`)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void start()
|
|
54
|
+
|
|
55
|
+
async function createAuth() {
|
|
56
|
+
if (!process.env.KORA_AUTH_SECRET) {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const oauth = await createOAuthConfig()
|
|
61
|
+
return createKoraAuthServer({
|
|
62
|
+
jwtSecret: process.env.KORA_AUTH_SECRET,
|
|
63
|
+
...(oauth ? { oauth } : {}),
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function createOAuthConfig(): Promise<CreateKoraAuthServerOptions['oauth'] | undefined> {
|
|
68
|
+
if (!process.env.KORA_GOOGLE_CLIENT_ID || !process.env.KORA_GOOGLE_REDIRECT_URI) {
|
|
69
|
+
return undefined
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const oauthStores = process.env.DATABASE_URL
|
|
73
|
+
? await createPostgresOAuthStores({ connectionString: process.env.DATABASE_URL })
|
|
74
|
+
: await createSqliteOAuthStores({
|
|
75
|
+
filename: process.env.KORA_AUTH_DB || './kora-auth.db',
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
providers: [
|
|
80
|
+
googleProvider({
|
|
81
|
+
clientId: process.env.KORA_GOOGLE_CLIENT_ID,
|
|
82
|
+
clientSecret: process.env.KORA_GOOGLE_CLIENT_SECRET,
|
|
83
|
+
redirectUri: process.env.KORA_GOOGLE_REDIRECT_URI,
|
|
84
|
+
pkce: process.env.KORA_OAUTH_PKCE === 'true' || !process.env.KORA_GOOGLE_CLIENT_SECRET,
|
|
85
|
+
}),
|
|
86
|
+
],
|
|
87
|
+
stateStore: oauthStores.stateStore,
|
|
88
|
+
linkedIdentityStore: oauthStores.linkedIdentityStore,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useAuth } from '@korajs/auth/vue'
|
|
3
|
+
import { useSyncStatus } from '@korajs/vue'
|
|
4
|
+
import { computed, ref } from 'vue'
|
|
5
|
+
import { useTodos } from './modules/todos/useTodos'
|
|
6
|
+
|
|
7
|
+
type Filter = 'all' | 'active' | 'completed'
|
|
8
|
+
|
|
9
|
+
const { allTodos, activeTodos, completedTodos, addTodo, toggleTodo, deleteTodo } = useTodos()
|
|
10
|
+
const syncStatus = useSyncStatus()
|
|
11
|
+
const { user, isAuthenticated, signInWithOAuth, signOut, error } = useAuth()
|
|
12
|
+
|
|
13
|
+
const filter = ref<Filter>('all')
|
|
14
|
+
const input = ref('')
|
|
15
|
+
|
|
16
|
+
const filteredTodos = computed(() => {
|
|
17
|
+
if (filter.value === 'active') return activeTodos.value
|
|
18
|
+
if (filter.value === 'completed') return completedTodos.value
|
|
19
|
+
return allTodos.value
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
function handleSubmit(): void {
|
|
23
|
+
const title = input.value.trim()
|
|
24
|
+
if (!title) return
|
|
25
|
+
addTodo.mutate({ title })
|
|
26
|
+
input.value = ''
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function clearCompleted(): void {
|
|
30
|
+
for (const todo of completedTodos.value) {
|
|
31
|
+
deleteTodo.mutate(todo.id)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function formatTime(timestamp: number): string {
|
|
36
|
+
const date = new Date(timestamp)
|
|
37
|
+
const now = new Date()
|
|
38
|
+
if (date.toDateString() === now.toDateString()) {
|
|
39
|
+
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
|
40
|
+
}
|
|
41
|
+
return date.toLocaleDateString([], { month: 'short', day: 'numeric' })
|
|
42
|
+
}
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<div class="app">
|
|
47
|
+
<div class="header">
|
|
48
|
+
<h1>My Tasks</h1>
|
|
49
|
+
<div class="header-actions">
|
|
50
|
+
<div class="sync-badge">
|
|
51
|
+
<span :class="['sync-dot', syncStatus.status]" />
|
|
52
|
+
<span>{{ syncStatus.status }}</span>
|
|
53
|
+
</div>
|
|
54
|
+
<button v-if="isAuthenticated" type="button" class="auth-button" @click="signOut()">
|
|
55
|
+
{{ user?.email || 'Sign out' }}
|
|
56
|
+
</button>
|
|
57
|
+
<button v-else type="button" class="auth-button" @click="signInWithOAuth('google')">
|
|
58
|
+
Sign in
|
|
59
|
+
</button>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<div v-if="error" class="auth-error">{{ error }}</div>
|
|
64
|
+
|
|
65
|
+
<div class="stats">
|
|
66
|
+
<div class="stat-card">
|
|
67
|
+
<div class="label">Total</div>
|
|
68
|
+
<div class="value muted">{{ allTodos.length }}</div>
|
|
69
|
+
</div>
|
|
70
|
+
<div class="stat-card">
|
|
71
|
+
<div class="label">Remaining</div>
|
|
72
|
+
<div class="value warning">{{ activeTodos.length }}</div>
|
|
73
|
+
</div>
|
|
74
|
+
<div class="stat-card">
|
|
75
|
+
<div class="label">Done</div>
|
|
76
|
+
<div class="value success">{{ completedTodos.length }}</div>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<form class="add-form" @submit.prevent="handleSubmit">
|
|
81
|
+
<input v-model="input" type="text" placeholder="What needs to be done?" />
|
|
82
|
+
<button type="submit" :disabled="!input.trim()">Add</button>
|
|
83
|
+
</form>
|
|
84
|
+
|
|
85
|
+
<div class="filters">
|
|
86
|
+
<button
|
|
87
|
+
v-for="f in (['all', 'active', 'completed'] as const)"
|
|
88
|
+
:key="f"
|
|
89
|
+
type="button"
|
|
90
|
+
:class="['filter-btn', { active: filter === f }]"
|
|
91
|
+
@click="filter = f"
|
|
92
|
+
>
|
|
93
|
+
{{ f.charAt(0).toUpperCase() + f.slice(1) }}
|
|
94
|
+
<span class="badge">
|
|
95
|
+
{{
|
|
96
|
+
f === 'all'
|
|
97
|
+
? allTodos.length
|
|
98
|
+
: f === 'active'
|
|
99
|
+
? activeTodos.length
|
|
100
|
+
: completedTodos.length
|
|
101
|
+
}}
|
|
102
|
+
</span>
|
|
103
|
+
</button>
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<div class="todo-list">
|
|
107
|
+
<div v-if="filteredTodos.length === 0" class="empty-state">
|
|
108
|
+
<template v-if="filter === 'all'">No tasks yet. Add one above!</template>
|
|
109
|
+
<template v-else-if="filter === 'active'">All caught up! No active tasks.</template>
|
|
110
|
+
<template v-else>No completed tasks yet.</template>
|
|
111
|
+
</div>
|
|
112
|
+
<div v-for="todo in filteredTodos" v-else :key="todo.id" class="todo-item">
|
|
113
|
+
<button
|
|
114
|
+
type="button"
|
|
115
|
+
:class="['toggle', { checked: todo.completed }]"
|
|
116
|
+
@click="toggleTodo.mutate(todo.id, { completed: !todo.completed })"
|
|
117
|
+
>
|
|
118
|
+
{{ todo.completed ? '✓' : '' }}
|
|
119
|
+
</button>
|
|
120
|
+
<span :class="['title', { done: todo.completed }]">{{ String(todo.title) }}</span>
|
|
121
|
+
<span v-if="todo.createdAt" class="time">{{ formatTime(Number(todo.createdAt)) }}</span>
|
|
122
|
+
<button type="button" class="delete-btn" @click="deleteTodo.mutate(todo.id)">×</button>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
|
|
126
|
+
<div v-if="allTodos.length > 0" class="footer">
|
|
127
|
+
<span>{{ activeTodos.length }} item{{ activeTodos.length !== 1 ? 's' : '' }} left</span>
|
|
128
|
+
<button v-if="completedTodos.length > 0" type="button" @click="clearCompleted">
|
|
129
|
+
Clear completed
|
|
130
|
+
</button>
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
<p class="branding">Powered by Kora — offline-first, real-time sync</p>
|
|
134
|
+
</div>
|
|
135
|
+
</template>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createKoraAuth } from '@korajs/auth'
|
|
2
|
+
|
|
3
|
+
export const authServerUrl =
|
|
4
|
+
import.meta.env.VITE_AUTH_URL || `${window.location.protocol}//${window.location.host}`
|
|
5
|
+
|
|
6
|
+
export const authClient = createKoraAuth({
|
|
7
|
+
serverUrl: authServerUrl,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export async function completeOAuthCallbackFromLocation(): Promise<void> {
|
|
11
|
+
const url = new URL(window.location.href)
|
|
12
|
+
const code = url.searchParams.get('code')
|
|
13
|
+
const state = url.searchParams.get('state')
|
|
14
|
+
const provider = url.searchParams.get('provider') || 'google'
|
|
15
|
+
|
|
16
|
+
if (!code || !state) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await authClient.completeOAuthSignIn(provider, { code, state })
|
|
21
|
+
url.searchParams.delete('code')
|
|
22
|
+
url.searchParams.delete('state')
|
|
23
|
+
url.searchParams.delete('provider')
|
|
24
|
+
window.history.replaceState({}, document.title, `${url.pathname}${url.search}${url.hash}`)
|
|
25
|
+
}
|