@batijs/cli 0.0.243 → 0.0.244
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/boilerplates/@batijs/drizzle/files/$package.json.js +8 -8
- package/dist/boilerplates/@batijs/drizzle/files/database/{db.ts → drizzleDb.ts} +1 -2
- package/dist/boilerplates/@batijs/drizzle/files/database/seed.ts +4 -3
- package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +1 -1
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzleDb.d.ts +1 -0
- package/dist/boilerplates/@batijs/express/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/express/files/express-entry.ts +20 -0
- package/dist/boilerplates/@batijs/fastify/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +20 -0
- package/dist/boilerplates/@batijs/h3/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +20 -0
- package/dist/boilerplates/@batijs/hattip/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +20 -0
- package/dist/boilerplates/@batijs/hono/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +20 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/$.env.js +23 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/$README.md.js +29 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +133 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/database/auth-actions.ts +54 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/database/schema/auth.ts +41 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/database/sqliteDb.ts +30 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/lib/lucia-auth.ts +96 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/pages/login/+guard.ts +11 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/pages/login/style.css +94 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +344 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/vike.d.ts +11 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/database/auth-actions.d.ts +9 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/database/schema/auth.d.ts +167 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/database/sqliteDb.d.ts +2 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/lib/lucia-auth.d.ts +43 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/pages/login/+guard.d.ts +3 -0
- package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +46 -0
- package/dist/boilerplates/@batijs/react/files/layouts/LayoutDefault.tsx +1 -0
- package/dist/boilerplates/@batijs/react/files/pages/+config.ts +1 -1
- package/dist/boilerplates/@batijs/react-lucia-auth/files/pages/login/+Page.tsx +96 -0
- package/dist/boilerplates/@batijs/react-lucia-auth/types/pages/login/+Page.d.ts +2 -0
- package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +3 -3
- package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +3 -3
- package/dist/boilerplates/@batijs/solid/files/layouts/LayoutDefault.tsx +1 -0
- package/dist/boilerplates/@batijs/solid/files/pages/+config.ts +1 -1
- package/dist/boilerplates/@batijs/solid-lucia-auth/files/pages/login/+Page.tsx +96 -0
- package/dist/boilerplates/@batijs/solid-lucia-auth/types/pages/login/+Page.d.ts +2 -0
- package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +3 -3
- package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +3 -3
- package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +3 -3
- package/dist/boilerplates/@batijs/vercel/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/vue/files/layouts/LayoutDefault.vue +2 -0
- package/dist/boilerplates/@batijs/vue/files/pages/+config.ts +1 -1
- package/dist/boilerplates/@batijs/vue-lucia-auth/files/pages/login/+Page.vue +87 -0
- package/dist/boilerplates/boilerplates.json +59 -0
- package/dist/index.js +1 -1
- package/package.json +5 -5
- package/dist/boilerplates/@batijs/drizzle/types/database/db.d.ts +0 -2
- /package/dist/boilerplates/@batijs/drizzle/files/database/{schema.ts → schema/todos.ts} +0 -0
- /package/dist/boilerplates/@batijs/drizzle/types/database/{schema.d.ts → schema/todos.d.ts} +0 -0
|
@@ -64,11 +64,11 @@ var require_package = __commonJS({
|
|
|
64
64
|
"./drizzle.config": {
|
|
65
65
|
types: "./dist/types/drizzle.config.d.ts"
|
|
66
66
|
},
|
|
67
|
-
"./database/
|
|
68
|
-
types: "./dist/types/database/
|
|
67
|
+
"./database/drizzleDb": {
|
|
68
|
+
types: "./dist/types/database/drizzleDb.d.ts"
|
|
69
69
|
},
|
|
70
|
-
"./database/
|
|
71
|
-
types: "./dist/types/database/
|
|
70
|
+
"./database/schema/todos": {
|
|
71
|
+
types: "./dist/types/database/schema/todos.d.ts"
|
|
72
72
|
},
|
|
73
73
|
"./database/seed": {
|
|
74
74
|
types: "./dist/types/database/seed.d.ts"
|
|
@@ -79,11 +79,11 @@ var require_package = __commonJS({
|
|
|
79
79
|
"drizzle.config": [
|
|
80
80
|
"./dist/types/drizzle.config.d.ts"
|
|
81
81
|
],
|
|
82
|
-
"database/
|
|
83
|
-
"./dist/types/database/
|
|
82
|
+
"database/drizzleDb": [
|
|
83
|
+
"./dist/types/database/drizzleDb.d.ts"
|
|
84
84
|
],
|
|
85
|
-
"database/
|
|
86
|
-
"./dist/types/database/
|
|
85
|
+
"database/schema/todos": [
|
|
86
|
+
"./dist/types/database/schema/todos.d.ts"
|
|
87
87
|
],
|
|
88
88
|
"database/seed": [
|
|
89
89
|
"./dist/types/database/seed.d.ts"
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Database from "better-sqlite3";
|
|
2
2
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
3
|
-
import * as schema from "./schema";
|
|
4
3
|
|
|
5
4
|
const sqlite = new Database("sqlite.db");
|
|
6
|
-
export const
|
|
5
|
+
export const drizzleDb = drizzle(sqlite);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { todoTable } from "./schema";
|
|
1
|
+
import { drizzleDb } from "./drizzleDb";
|
|
2
|
+
import { todoTable } from "./schema/todos";
|
|
3
3
|
|
|
4
4
|
async function seed() {
|
|
5
|
-
|
|
5
|
+
drizzleDb
|
|
6
|
+
.insert(todoTable)
|
|
6
7
|
.values([{ text: "Buy milk" }, { text: "Buy strawberries" }])
|
|
7
8
|
.run();
|
|
8
9
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const drizzleDb: import("drizzle-orm/better-sqlite3").BetterSQLite3Database<Record<string, never>>;
|
|
@@ -45,6 +45,7 @@ var require_package = __commonJS({
|
|
|
45
45
|
"@batijs/authjs": "workspace:*",
|
|
46
46
|
"@batijs/compile": "workspace:*",
|
|
47
47
|
"@batijs/firebase-auth": "workspace:*",
|
|
48
|
+
"@batijs/lucia-auth": "workspace:*",
|
|
48
49
|
"@batijs/shared-server": "workspace:^",
|
|
49
50
|
"@batijs/shared-todo": "workspace:^",
|
|
50
51
|
"@batijs/telefunc": "workspace:*",
|
|
@@ -8,6 +8,15 @@ import {
|
|
|
8
8
|
firebaseAuthLogoutHandler,
|
|
9
9
|
firebaseAuthMiddleware,
|
|
10
10
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
11
|
+
import {
|
|
12
|
+
luciaAuthLoginHandler,
|
|
13
|
+
luciaAuthLogoutHandler,
|
|
14
|
+
luciaAuthMiddleware,
|
|
15
|
+
luciaAuthSignupHandler,
|
|
16
|
+
luciaCsrfMiddleware,
|
|
17
|
+
luciaGithubCallbackHandler,
|
|
18
|
+
luciaGithubLoginHandler,
|
|
19
|
+
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
11
20
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
12
21
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
13
22
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
@@ -63,6 +72,17 @@ async function startServer() {
|
|
|
63
72
|
app.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler));
|
|
64
73
|
}
|
|
65
74
|
|
|
75
|
+
if (BATI.has("lucia-auth")) {
|
|
76
|
+
app.use(createMiddleware(luciaCsrfMiddleware));
|
|
77
|
+
app.use(createMiddleware(luciaAuthMiddleware));
|
|
78
|
+
|
|
79
|
+
app.post("/api/signup", createHandler(luciaAuthSignupHandler));
|
|
80
|
+
app.post("/api/login", createHandler(luciaAuthLoginHandler));
|
|
81
|
+
app.post("/api/logout", createHandler(luciaAuthLogoutHandler));
|
|
82
|
+
app.get("/api/login/github", createHandler(luciaGithubLoginHandler));
|
|
83
|
+
app.get("/api/login/github/callback", createHandler(luciaGithubCallbackHandler));
|
|
84
|
+
}
|
|
85
|
+
|
|
66
86
|
if (BATI.has("trpc")) {
|
|
67
87
|
/**
|
|
68
88
|
* tRPC route
|
|
@@ -45,6 +45,7 @@ var require_package = __commonJS({
|
|
|
45
45
|
"@batijs/authjs": "workspace:*",
|
|
46
46
|
"@batijs/compile": "workspace:*",
|
|
47
47
|
"@batijs/firebase-auth": "workspace:*",
|
|
48
|
+
"@batijs/lucia-auth": "workspace:*",
|
|
48
49
|
"@batijs/shared-server": "workspace:^",
|
|
49
50
|
"@batijs/shared-todo": "workspace:^",
|
|
50
51
|
"@batijs/telefunc": "workspace:^",
|
|
@@ -8,6 +8,15 @@ import {
|
|
|
8
8
|
firebaseAuthLogoutHandler,
|
|
9
9
|
firebaseAuthMiddleware,
|
|
10
10
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
11
|
+
import {
|
|
12
|
+
luciaAuthLoginHandler,
|
|
13
|
+
luciaAuthLogoutHandler,
|
|
14
|
+
luciaAuthMiddleware,
|
|
15
|
+
luciaAuthSignupHandler,
|
|
16
|
+
luciaCsrfMiddleware,
|
|
17
|
+
luciaGithubCallbackHandler,
|
|
18
|
+
luciaGithubLoginHandler,
|
|
19
|
+
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
11
20
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
12
21
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
13
22
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
@@ -111,6 +120,17 @@ async function startServer() {
|
|
|
111
120
|
app.post("/api/sessionLogout", handlerAdapter(firebaseAuthLogoutHandler));
|
|
112
121
|
}
|
|
113
122
|
|
|
123
|
+
if (BATI.has("lucia-auth")) {
|
|
124
|
+
app.addHook("onRequest", handlerAdapter(luciaCsrfMiddleware));
|
|
125
|
+
app.addHook("onRequest", handlerAdapter(luciaAuthMiddleware));
|
|
126
|
+
|
|
127
|
+
app.post("/api/signup", handlerAdapter(luciaAuthSignupHandler));
|
|
128
|
+
app.post("/api/login", handlerAdapter(luciaAuthLoginHandler));
|
|
129
|
+
app.post("/api/logout", handlerAdapter(luciaAuthLogoutHandler));
|
|
130
|
+
app.get("/api/login/github", handlerAdapter(luciaGithubLoginHandler));
|
|
131
|
+
app.get("/api/login/github/callback", handlerAdapter(luciaGithubCallbackHandler));
|
|
132
|
+
}
|
|
133
|
+
|
|
114
134
|
if (BATI.has("trpc")) {
|
|
115
135
|
/**
|
|
116
136
|
* tRPC route
|
|
@@ -45,6 +45,7 @@ var require_package = __commonJS({
|
|
|
45
45
|
"@batijs/authjs": "workspace:*",
|
|
46
46
|
"@batijs/compile": "workspace:*",
|
|
47
47
|
"@batijs/firebase-auth": "workspace:*",
|
|
48
|
+
"@batijs/lucia-auth": "workspace:*",
|
|
48
49
|
"@batijs/shared-server": "workspace:^",
|
|
49
50
|
"@batijs/shared-todo": "workspace:^",
|
|
50
51
|
"@batijs/telefunc": "workspace:^",
|
|
@@ -9,6 +9,15 @@ import {
|
|
|
9
9
|
firebaseAuthLogoutHandler,
|
|
10
10
|
firebaseAuthMiddleware,
|
|
11
11
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
12
|
+
import {
|
|
13
|
+
luciaAuthLoginHandler,
|
|
14
|
+
luciaAuthLogoutHandler,
|
|
15
|
+
luciaAuthMiddleware,
|
|
16
|
+
luciaAuthSignupHandler,
|
|
17
|
+
luciaCsrfMiddleware,
|
|
18
|
+
luciaGithubCallbackHandler,
|
|
19
|
+
luciaGithubLoginHandler,
|
|
20
|
+
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
12
21
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
13
22
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
14
23
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
@@ -87,6 +96,17 @@ async function startServer() {
|
|
|
87
96
|
router.post("/api/sessionLogout", fromWebMiddleware(firebaseAuthLogoutHandler));
|
|
88
97
|
}
|
|
89
98
|
|
|
99
|
+
if (BATI.has("lucia-auth")) {
|
|
100
|
+
app.use(fromWebMiddleware(luciaCsrfMiddleware));
|
|
101
|
+
app.use(fromWebMiddleware(luciaAuthMiddleware));
|
|
102
|
+
|
|
103
|
+
router.post("/api/signup", fromWebMiddleware(luciaAuthSignupHandler));
|
|
104
|
+
router.post("/api/login", fromWebMiddleware(luciaAuthLoginHandler));
|
|
105
|
+
router.post("/api/logout", fromWebMiddleware(luciaAuthLogoutHandler));
|
|
106
|
+
router.get("/api/login/github", fromWebMiddleware(luciaGithubLoginHandler));
|
|
107
|
+
router.get("/api/login/github/callback", fromWebMiddleware(luciaGithubCallbackHandler));
|
|
108
|
+
}
|
|
109
|
+
|
|
90
110
|
if (BATI.has("trpc")) {
|
|
91
111
|
/**
|
|
92
112
|
* tRPC route
|
|
@@ -45,6 +45,7 @@ var require_package = __commonJS({
|
|
|
45
45
|
"@batijs/authjs": "workspace:*",
|
|
46
46
|
"@batijs/compile": "workspace:*",
|
|
47
47
|
"@batijs/firebase-auth": "workspace:*",
|
|
48
|
+
"@batijs/lucia-auth": "workspace:*",
|
|
48
49
|
"@batijs/shared-server": "workspace:^",
|
|
49
50
|
"@batijs/shared-todo": "workspace:^",
|
|
50
51
|
"@batijs/telefunc": "workspace:^",
|
|
@@ -6,6 +6,15 @@ import {
|
|
|
6
6
|
firebaseAuthLogoutHandler,
|
|
7
7
|
firebaseAuthMiddleware,
|
|
8
8
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
9
|
+
import {
|
|
10
|
+
luciaAuthLoginHandler,
|
|
11
|
+
luciaAuthLogoutHandler,
|
|
12
|
+
luciaAuthMiddleware,
|
|
13
|
+
luciaAuthSignupHandler,
|
|
14
|
+
luciaCsrfMiddleware,
|
|
15
|
+
luciaGithubCallbackHandler,
|
|
16
|
+
luciaGithubLoginHandler,
|
|
17
|
+
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
9
18
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
10
19
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
11
20
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
@@ -82,6 +91,17 @@ if (BATI.has("firebase-auth")) {
|
|
|
82
91
|
router.post("/api/sessionLogout", handlerAdapter(firebaseAuthLogoutHandler));
|
|
83
92
|
}
|
|
84
93
|
|
|
94
|
+
if (BATI.has("lucia-auth")) {
|
|
95
|
+
router.use(handlerAdapter(luciaCsrfMiddleware));
|
|
96
|
+
router.use(handlerAdapter(luciaAuthMiddleware));
|
|
97
|
+
|
|
98
|
+
router.post("/api/signup", handlerAdapter(luciaAuthSignupHandler));
|
|
99
|
+
router.post("/api/login", handlerAdapter(luciaAuthLoginHandler));
|
|
100
|
+
router.post("/api/logout", handlerAdapter(luciaAuthLogoutHandler));
|
|
101
|
+
router.get("/api/login/github", handlerAdapter(luciaGithubLoginHandler));
|
|
102
|
+
router.get("/api/login/github/callback", handlerAdapter(luciaGithubCallbackHandler));
|
|
103
|
+
}
|
|
104
|
+
|
|
85
105
|
if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
86
106
|
router.post("/api/todo/create", handlerAdapter(createTodoHandler));
|
|
87
107
|
}
|
|
@@ -45,6 +45,7 @@ var require_package = __commonJS({
|
|
|
45
45
|
"@batijs/authjs": "workspace:*",
|
|
46
46
|
"@batijs/compile": "workspace:*",
|
|
47
47
|
"@batijs/firebase-auth": "workspace:*",
|
|
48
|
+
"@batijs/lucia-auth": "workspace:*",
|
|
48
49
|
"@batijs/shared-server": "workspace:^",
|
|
49
50
|
"@batijs/shared-todo": "workspace:^",
|
|
50
51
|
"@batijs/telefunc": "workspace:^",
|
|
@@ -6,6 +6,15 @@ import {
|
|
|
6
6
|
firebaseAuthLogoutHandler,
|
|
7
7
|
firebaseAuthMiddleware,
|
|
8
8
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
9
|
+
import {
|
|
10
|
+
luciaAuthLoginHandler,
|
|
11
|
+
luciaAuthLogoutHandler,
|
|
12
|
+
luciaAuthMiddleware,
|
|
13
|
+
luciaAuthSignupHandler,
|
|
14
|
+
luciaCsrfMiddleware,
|
|
15
|
+
luciaGithubCallbackHandler,
|
|
16
|
+
luciaGithubLoginHandler,
|
|
17
|
+
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
9
18
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
10
19
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
11
20
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
@@ -37,6 +46,17 @@ if (BATI.has("firebase-auth")) {
|
|
|
37
46
|
app.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler));
|
|
38
47
|
}
|
|
39
48
|
|
|
49
|
+
if (BATI.has("lucia-auth")) {
|
|
50
|
+
app.use(createMiddleware(luciaCsrfMiddleware));
|
|
51
|
+
app.use(createMiddleware(luciaAuthMiddleware));
|
|
52
|
+
|
|
53
|
+
app.post("/api/signup", createHandler(luciaAuthSignupHandler));
|
|
54
|
+
app.post("/api/login", createHandler(luciaAuthLoginHandler));
|
|
55
|
+
app.post("/api/logout", createHandler(luciaAuthLogoutHandler));
|
|
56
|
+
app.get("/api/login/github", createHandler(luciaGithubLoginHandler));
|
|
57
|
+
app.get("/api/login/github/callback", createHandler(luciaGithubCallbackHandler));
|
|
58
|
+
}
|
|
59
|
+
|
|
40
60
|
if (BATI.has("trpc")) {
|
|
41
61
|
/**
|
|
42
62
|
* tRPC route
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// files/$.env.ts
|
|
2
|
+
import { appendToEnv } from "@batijs/core";
|
|
3
|
+
async function getEnv(props) {
|
|
4
|
+
const githubClientId = process.env.TEST_GITHUB_CLIENT_ID;
|
|
5
|
+
const githubClientSecret = process.env.TEST_GITHUB_CLIENT_SECRET;
|
|
6
|
+
let envContent = await props.readfile?.();
|
|
7
|
+
envContent = appendToEnv(
|
|
8
|
+
envContent,
|
|
9
|
+
"GITHUB_CLIENT_ID",
|
|
10
|
+
githubClientId ?? "",
|
|
11
|
+
"GitHub Client ID. Used for authentication"
|
|
12
|
+
);
|
|
13
|
+
envContent = appendToEnv(
|
|
14
|
+
envContent,
|
|
15
|
+
"GITHUB_CLIENT_SECRET",
|
|
16
|
+
githubClientSecret ?? "",
|
|
17
|
+
"GitHub Client Secret. Used for authentication"
|
|
18
|
+
);
|
|
19
|
+
return envContent;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
getEnv as default
|
|
23
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// files/$README.md.ts
|
|
2
|
+
import { loadReadme } from "@batijs/core";
|
|
3
|
+
async function getReadme(props) {
|
|
4
|
+
const content = await loadReadme(props);
|
|
5
|
+
const todo = `
|
|
6
|
+
## *Example: Lucia Auth with GitHub OAuth*
|
|
7
|
+
- Create a [GitHub OAuth app](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app). Set the Authorization callback URL to \`http://localhost:3000/api/login/github/callback\`.
|
|
8
|
+
- Copy your \`Client ID\` and \`Client Secret\` then paste it in \`.env\` file like this:
|
|
9
|
+
|
|
10
|
+
\`\`\`env
|
|
11
|
+
// .env
|
|
12
|
+
GITHUB_CLIENT_ID=<Client ID>
|
|
13
|
+
GITHUB_CLIENT_SECRET=<Client Secret>
|
|
14
|
+
\`\`\`
|
|
15
|
+
|
|
16
|
+
- Read more [Lucia Auth: OAuth](https://lucia-auth.com/guides/oauth/)
|
|
17
|
+
|
|
18
|
+
> [!NOTE]
|
|
19
|
+
> Username & Password signup route : \`http://localhost:3000/api/signup\`.
|
|
20
|
+
> Username & Password login route : \`http://localhost:3000/api/login\`.
|
|
21
|
+
> GitHub login route : \`http://localhost:3000/api/login/github\`.
|
|
22
|
+
> Logout route : \`http://localhost:3000/api/auth/logout\`.
|
|
23
|
+
`;
|
|
24
|
+
content.addTodo(todo);
|
|
25
|
+
return content.finalize();
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
getReadme as default
|
|
29
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// package.json
|
|
28
|
+
var require_package = __commonJS({
|
|
29
|
+
"package.json"(exports, module) {
|
|
30
|
+
module.exports = {
|
|
31
|
+
name: "@batijs/lucia-auth",
|
|
32
|
+
private: true,
|
|
33
|
+
version: "0.0.1",
|
|
34
|
+
description: "",
|
|
35
|
+
type: "module",
|
|
36
|
+
scripts: {
|
|
37
|
+
"check-types": "tsc --noEmit",
|
|
38
|
+
build: "bati-compile-boilerplate"
|
|
39
|
+
},
|
|
40
|
+
keywords: [],
|
|
41
|
+
author: "",
|
|
42
|
+
license: "MIT",
|
|
43
|
+
devDependencies: {
|
|
44
|
+
"@batijs/compile": "workspace:*",
|
|
45
|
+
"@batijs/drizzle": "workspace:*",
|
|
46
|
+
"@lucia-auth/adapter-drizzle": "^1.1.0",
|
|
47
|
+
"@lucia-auth/adapter-sqlite": "^3.0.2",
|
|
48
|
+
"@types/better-sqlite3": "^7.6.11",
|
|
49
|
+
"@types/cookie": "^0.6.0",
|
|
50
|
+
"@types/node": "^18.19.14",
|
|
51
|
+
arctic: "^1.9.2",
|
|
52
|
+
"better-sqlite3": "^11.1.2",
|
|
53
|
+
cookie: "^0.6.0",
|
|
54
|
+
dotenv: "^16.4.5",
|
|
55
|
+
"drizzle-orm": "^0.33.0",
|
|
56
|
+
lucia: "^3.2.0",
|
|
57
|
+
vike: "^0.4.183",
|
|
58
|
+
vite: "^5.4.0"
|
|
59
|
+
},
|
|
60
|
+
dependencies: {
|
|
61
|
+
"@batijs/core": "workspace:*"
|
|
62
|
+
},
|
|
63
|
+
files: [
|
|
64
|
+
"dist/"
|
|
65
|
+
],
|
|
66
|
+
bati: {
|
|
67
|
+
if: {
|
|
68
|
+
flag: "lucia-auth"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
exports: {
|
|
72
|
+
"./database/sqliteDb": {
|
|
73
|
+
types: "./dist/types/database/sqliteDb.d.ts"
|
|
74
|
+
},
|
|
75
|
+
"./database/schema/auth": {
|
|
76
|
+
types: "./dist/types/database/schema/auth.d.ts"
|
|
77
|
+
},
|
|
78
|
+
"./database/auth-actions": {
|
|
79
|
+
types: "./dist/types/database/auth-actions.d.ts"
|
|
80
|
+
},
|
|
81
|
+
"./lib/lucia-auth": {
|
|
82
|
+
types: "./dist/types/lib/lucia-auth.d.ts"
|
|
83
|
+
},
|
|
84
|
+
"./pages/login/+guard": {
|
|
85
|
+
types: "./dist/types/pages/login/+guard.d.ts"
|
|
86
|
+
},
|
|
87
|
+
"./server/lucia-auth-handlers": {
|
|
88
|
+
types: "./dist/types/server/lucia-auth-handlers.d.ts"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
typesVersions: {
|
|
92
|
+
"*": {
|
|
93
|
+
"database/sqliteDb": [
|
|
94
|
+
"./dist/types/database/sqliteDb.d.ts"
|
|
95
|
+
],
|
|
96
|
+
"database/schema/auth": [
|
|
97
|
+
"./dist/types/database/schema/auth.d.ts"
|
|
98
|
+
],
|
|
99
|
+
"database/auth-actions": [
|
|
100
|
+
"./dist/types/database/auth-actions.d.ts"
|
|
101
|
+
],
|
|
102
|
+
"lib/lucia-auth": [
|
|
103
|
+
"./dist/types/lib/lucia-auth.d.ts"
|
|
104
|
+
],
|
|
105
|
+
"pages/login/+guard": [
|
|
106
|
+
"./dist/types/pages/login/+guard.d.ts"
|
|
107
|
+
],
|
|
108
|
+
"server/lucia-auth-handlers": [
|
|
109
|
+
"./dist/types/server/lucia-auth-handlers.d.ts"
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// files/$package.json.ts
|
|
118
|
+
import { addDependency, loadAsJson } from "@batijs/core";
|
|
119
|
+
async function getPackageJson(props) {
|
|
120
|
+
const packageJson = await loadAsJson(props);
|
|
121
|
+
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
|
|
122
|
+
devDependencies: ["dotenv", "@types/better-sqlite3", "@types/cookie"],
|
|
123
|
+
dependencies: [
|
|
124
|
+
"arctic",
|
|
125
|
+
"cookie",
|
|
126
|
+
"lucia",
|
|
127
|
+
...props.meta.BATI.has("drizzle") ? ["@lucia-auth/adapter-drizzle"] : ["better-sqlite3", "@lucia-auth/adapter-sqlite"]
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
getPackageJson as default
|
|
133
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
|
|
2
|
+
import { sqliteDb } from "./sqliteDb";
|
|
3
|
+
import { userTable, oauthAccountTable } from "./schema/auth";
|
|
4
|
+
import { eq, and } from "drizzle-orm";
|
|
5
|
+
|
|
6
|
+
export function getExistingUser(username: string) {
|
|
7
|
+
if (BATI.has("drizzle")) {
|
|
8
|
+
return drizzleDb.select().from(userTable).where(eq(userTable.username, username)).get();
|
|
9
|
+
} else {
|
|
10
|
+
return sqliteDb.prepare("SELECT * FROM users WHERE username = ?").get(username);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getExistingAccount(providerId: string, providerUserId: number) {
|
|
15
|
+
if (BATI.has("drizzle")) {
|
|
16
|
+
return drizzleDb
|
|
17
|
+
.select()
|
|
18
|
+
.from(oauthAccountTable)
|
|
19
|
+
.where(and(eq(oauthAccountTable.providerId, providerId), eq(oauthAccountTable.providerUserId, providerUserId)))
|
|
20
|
+
.get();
|
|
21
|
+
} else {
|
|
22
|
+
return sqliteDb
|
|
23
|
+
.prepare("SELECT * FROM oauth_accounts WHERE provider_id = ? AND provider_user_id = ?")
|
|
24
|
+
.get(providerId, providerUserId);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function validateInput(username: string | null, password: string | null) {
|
|
29
|
+
const error: {
|
|
30
|
+
username: string | null;
|
|
31
|
+
password: string | null;
|
|
32
|
+
} = {
|
|
33
|
+
username: null,
|
|
34
|
+
password: null,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (!username || username.length < 3 || username.length > 31 || !/^[a-z0-9_-]+$/.test(username)) {
|
|
38
|
+
error.username = "Invalid username";
|
|
39
|
+
}
|
|
40
|
+
if (!password || password.length < 6 || password.length > 255) {
|
|
41
|
+
error.password = "Invalid password";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (error.username || error.password) {
|
|
45
|
+
return {
|
|
46
|
+
error,
|
|
47
|
+
success: false,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
error,
|
|
52
|
+
success: true,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
2
|
+
import { integer, primaryKey, sqliteTable, text, int } from "drizzle-orm/sqlite-core";
|
|
3
|
+
|
|
4
|
+
export const userTable = sqliteTable("users", {
|
|
5
|
+
id: text("id").notNull().primaryKey(),
|
|
6
|
+
username: text("username").notNull().unique(),
|
|
7
|
+
password: text("password"),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const oauthAccountTable = sqliteTable(
|
|
11
|
+
"oauth_accounts",
|
|
12
|
+
{
|
|
13
|
+
providerId: text("provider_id").notNull(),
|
|
14
|
+
providerUserId: int("provider_user_id").notNull(),
|
|
15
|
+
userId: text("user_id")
|
|
16
|
+
.notNull()
|
|
17
|
+
.references(() => userTable.id, {
|
|
18
|
+
onUpdate: "cascade",
|
|
19
|
+
onDelete: "cascade",
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
(table) => {
|
|
23
|
+
return {
|
|
24
|
+
pk: primaryKey({ columns: [table.providerId, table.providerUserId] }),
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const sessionTable = sqliteTable("sessions", {
|
|
30
|
+
id: text("id").notNull().primaryKey(),
|
|
31
|
+
userId: text("user_id")
|
|
32
|
+
.notNull()
|
|
33
|
+
.references(() => userTable.id, {
|
|
34
|
+
onUpdate: "cascade",
|
|
35
|
+
onDelete: "cascade",
|
|
36
|
+
}),
|
|
37
|
+
expiresAt: integer("expires_at").notNull(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export type UserItem = typeof userTable.$inferSelect;
|
|
41
|
+
export type UserInsert = typeof userTable.$inferInsert;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
2
|
+
import sqlite, { type Database } from "better-sqlite3";
|
|
3
|
+
|
|
4
|
+
export const sqliteDb: Database = sqlite(":memory:");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* SQLite Schema
|
|
8
|
+
*
|
|
9
|
+
* @link {@see https://lucia-auth.com/database/sqlite#schema}
|
|
10
|
+
*/
|
|
11
|
+
sqliteDb.exec(`CREATE TABLE IF NOT EXISTS users (
|
|
12
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
13
|
+
username TEXT NOT NULL UNIQUE,
|
|
14
|
+
password TEXT
|
|
15
|
+
)`);
|
|
16
|
+
|
|
17
|
+
sqliteDb.exec(`CREATE TABLE IF NOT EXISTS oauth_accounts (
|
|
18
|
+
provider_id TEXT NOT NULL,
|
|
19
|
+
provider_user_id INTEGER NOT NULL,
|
|
20
|
+
user_id TEXT NOT NULL,
|
|
21
|
+
PRIMARY KEY (provider_id, provider_user_id),
|
|
22
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE cascade ON DELETE cascade
|
|
23
|
+
)`);
|
|
24
|
+
|
|
25
|
+
sqliteDb.exec(`CREATE TABLE IF NOT EXISTS sessions (
|
|
26
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
27
|
+
expires_at INTEGER NOT NULL,
|
|
28
|
+
user_id TEXT NOT NULL,
|
|
29
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE cascade ON DELETE cascade
|
|
30
|
+
)`);
|