@batijs/cli 0.0.244 → 0.0.246
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/authjs/files/$package.json.js +92 -0
- package/dist/boilerplates/@batijs/authjs/files/server/authjs-handler.ts +14 -13
- package/dist/boilerplates/@batijs/authjs/types/server/authjs-handler.d.ts +4 -2
- package/dist/boilerplates/@batijs/cloudflare/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/compiled/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/eslint/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/express/files/$package.json.js +3 -4
- package/dist/boilerplates/@batijs/express/files/express-entry.ts +20 -18
- package/dist/boilerplates/@batijs/fastify/files/$package.json.js +5 -6
- package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +22 -54
- package/dist/boilerplates/@batijs/fastify/types/fastify-entry.d.ts +0 -4
- package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +5 -4
- package/dist/boilerplates/@batijs/firebase-auth/files/server/firebase-auth-middleware.ts +16 -18
- package/dist/boilerplates/@batijs/firebase-auth/types/server/firebase-auth-middleware.d.ts +8 -3
- package/dist/boilerplates/@batijs/h3/files/$package.json.js +4 -2
- package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +22 -33
- package/dist/boilerplates/@batijs/h3/types/h3-entry.d.ts +0 -4
- package/dist/boilerplates/@batijs/hattip/files/$package.json.js +4 -3
- package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +22 -33
- package/dist/boilerplates/@batijs/hono/files/$package.json.js +6 -15
- package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +19 -17
- package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +4 -2
- package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +41 -45
- package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +22 -10
- package/dist/boilerplates/@batijs/react/files/$package.json.js +4 -4
- package/dist/boilerplates/@batijs/shared/files/package.json +2 -2
- package/dist/boilerplates/@batijs/shared/files/vite.config.ts +1 -1
- package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +103 -0
- package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +3 -5
- package/dist/boilerplates/@batijs/shared-server/files/server/vike-handler.ts +3 -5
- package/dist/boilerplates/@batijs/shared-server/types/server/create-todo-handler.d.ts +2 -1
- package/dist/boilerplates/@batijs/shared-server/types/server/vike-handler.d.ts +2 -1
- package/dist/boilerplates/@batijs/solid/files/$package.json.js +5 -5
- package/dist/boilerplates/@batijs/tailwindcss/files/$package.json.js +3 -3
- package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +4 -3
- package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +3 -5
- package/dist/boilerplates/@batijs/telefunc/types/server/telefunc-handler.d.ts +2 -1
- package/dist/boilerplates/@batijs/trpc/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +4 -3
- package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +3 -6
- package/dist/boilerplates/@batijs/ts-rest/types/server/ts-rest-handler.d.ts +2 -1
- package/dist/boilerplates/@batijs/vercel/files/$package.json.js +4 -4
- package/dist/boilerplates/@batijs/vue/files/$package.json.js +7 -7
- package/dist/boilerplates/@batijs/vue/types/pages/+config.d.ts +6 -0
- package/dist/{chunk-MFJ4ET44.js → chunk-FWD3UPBV.js} +5 -5
- package/dist/index.js +14 -14
- package/dist/{prompt-SUR66HP4.js → prompt-EYFUFJSI.js} +4 -4
- package/package.json +8 -8
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
firebaseAuthMiddleware,
|
|
11
11
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
12
12
|
import {
|
|
13
|
+
luciaAuthContextMiddleware,
|
|
14
|
+
luciaAuthCookieMiddleware,
|
|
13
15
|
luciaAuthLoginHandler,
|
|
14
16
|
luciaAuthLogoutHandler,
|
|
15
|
-
luciaAuthMiddleware,
|
|
16
17
|
luciaAuthSignupHandler,
|
|
17
18
|
luciaCsrfMiddleware,
|
|
18
19
|
luciaGithubCallbackHandler,
|
|
@@ -27,8 +28,9 @@ import installCrypto from "@hattip/polyfills/crypto";
|
|
|
27
28
|
import installGetSetCookie from "@hattip/polyfills/get-set-cookie";
|
|
28
29
|
import installWhatwgNodeFetch from "@hattip/polyfills/whatwg-node";
|
|
29
30
|
import { type NodeHTTPCreateContextFnOptions, nodeHTTPRequestHandler } from "@trpc/server/adapters/node-http";
|
|
30
|
-
import { createApp, createRouter, eventHandler, fromNodeMiddleware, toNodeListener
|
|
31
|
+
import { createApp, createRouter, eventHandler, fromNodeMiddleware, toNodeListener } from "h3";
|
|
31
32
|
import serveStatic from "serve-static";
|
|
33
|
+
import { createHandler, createMiddleware } from "@universal-middleware/h3";
|
|
32
34
|
|
|
33
35
|
installWhatwgNodeFetch();
|
|
34
36
|
installGetSetCookie();
|
|
@@ -40,20 +42,6 @@ const root = __dirname;
|
|
|
40
42
|
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
41
43
|
const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678;
|
|
42
44
|
|
|
43
|
-
interface Middleware<Context extends Record<string | number | symbol, unknown>> {
|
|
44
|
-
(request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function fromWebMiddleware<Context extends Record<string | number | symbol, unknown>>(
|
|
48
|
-
handler: Middleware<Context>,
|
|
49
|
-
) {
|
|
50
|
-
return eventHandler((event) => {
|
|
51
|
-
const ctx = event.context as unknown as Record<string, unknown>;
|
|
52
|
-
ctx.context ??= {};
|
|
53
|
-
return handler(toWebRequest(event), ctx.context as Context);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
45
|
export default await startServer();
|
|
58
46
|
|
|
59
47
|
async function startServer() {
|
|
@@ -81,30 +69,31 @@ async function startServer() {
|
|
|
81
69
|
/**
|
|
82
70
|
* Append Auth.js session to context
|
|
83
71
|
**/
|
|
84
|
-
app.use(
|
|
72
|
+
app.use(createMiddleware(authjsSessionMiddleware)());
|
|
85
73
|
|
|
86
74
|
/**
|
|
87
75
|
* Auth.js route
|
|
88
76
|
* @link {@see https://authjs.dev/getting-started/installation}
|
|
89
77
|
**/
|
|
90
|
-
router.use("/api/auth/**",
|
|
78
|
+
router.use("/api/auth/**", createHandler(authjsHandler)());
|
|
91
79
|
}
|
|
92
80
|
|
|
93
81
|
if (BATI.has("firebase-auth")) {
|
|
94
|
-
app.use(
|
|
95
|
-
router.post("/api/sessionLogin",
|
|
96
|
-
router.post("/api/sessionLogout",
|
|
82
|
+
app.use(createMiddleware(firebaseAuthMiddleware)());
|
|
83
|
+
router.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler)());
|
|
84
|
+
router.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler)());
|
|
97
85
|
}
|
|
98
86
|
|
|
99
87
|
if (BATI.has("lucia-auth")) {
|
|
100
|
-
app.use(
|
|
101
|
-
app.use(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
router.post("/api/
|
|
105
|
-
router.post("/api/
|
|
106
|
-
router.
|
|
107
|
-
router.get("/api/login/github
|
|
88
|
+
app.use(createMiddleware(luciaCsrfMiddleware)());
|
|
89
|
+
app.use(createMiddleware(luciaAuthContextMiddleware)());
|
|
90
|
+
app.use(createMiddleware(luciaAuthCookieMiddleware)());
|
|
91
|
+
|
|
92
|
+
router.post("/api/signup", createHandler(luciaAuthSignupHandler)());
|
|
93
|
+
router.post("/api/login", createHandler(luciaAuthLoginHandler)());
|
|
94
|
+
router.post("/api/logout", createHandler(luciaAuthLogoutHandler)());
|
|
95
|
+
router.get("/api/login/github", createHandler(luciaGithubLoginHandler)());
|
|
96
|
+
router.get("/api/login/github/callback", createHandler(luciaGithubCallbackHandler)());
|
|
108
97
|
}
|
|
109
98
|
|
|
110
99
|
if (BATI.has("trpc")) {
|
|
@@ -135,15 +124,15 @@ async function startServer() {
|
|
|
135
124
|
*
|
|
136
125
|
* @link {@see https://telefunc.com}
|
|
137
126
|
**/
|
|
138
|
-
router.post("/_telefunc",
|
|
127
|
+
router.post("/_telefunc", createHandler(telefuncHandler)());
|
|
139
128
|
}
|
|
140
129
|
|
|
141
130
|
if (BATI.has("ts-rest")) {
|
|
142
|
-
router.use("/api/**",
|
|
131
|
+
router.use("/api/**", createHandler(tsRestHandler)());
|
|
143
132
|
}
|
|
144
133
|
|
|
145
134
|
if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
146
|
-
router.post("/api/todo/create",
|
|
135
|
+
router.post("/api/todo/create", createHandler(createTodoHandler)());
|
|
147
136
|
}
|
|
148
137
|
|
|
149
138
|
/**
|
|
@@ -151,7 +140,7 @@ async function startServer() {
|
|
|
151
140
|
*
|
|
152
141
|
* @link {@see https://vike.dev}
|
|
153
142
|
**/
|
|
154
|
-
router.use("/**",
|
|
143
|
+
router.use("/**", createHandler(vikeHandler)());
|
|
155
144
|
|
|
156
145
|
app.use(router);
|
|
157
146
|
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import { type IncomingMessage, type ServerResponse } from "node:http";
|
|
3
|
-
interface Middleware<Context extends Record<string | number | symbol, unknown>> {
|
|
4
|
-
(request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
|
|
5
|
-
}
|
|
6
|
-
export declare function fromWebMiddleware<Context extends Record<string | number | symbol, unknown>>(handler: Middleware<Context>): import("h3").EventHandler<import("h3").EventHandlerRequest, void | Response | Promise<Response> | Promise<void>>;
|
|
7
3
|
declare const _default: import("http").Server<typeof IncomingMessage, typeof ServerResponse>;
|
|
8
4
|
export default _default;
|
|
@@ -58,12 +58,13 @@ var require_package = __commonJS({
|
|
|
58
58
|
"@hattip/vite": "^0.0.47",
|
|
59
59
|
"@trpc/server": "^10.45.2",
|
|
60
60
|
"@types/node": "^18.19.14",
|
|
61
|
+
"@universal-middleware/hattip": "^0.2.1",
|
|
61
62
|
"cross-env": "^7.0.3",
|
|
62
63
|
dotenv: "^16.4.5",
|
|
63
64
|
hattip: "^0.0.33",
|
|
64
65
|
telefunc: "^0.1.76",
|
|
65
|
-
vike: "^0.4.
|
|
66
|
-
vite: "^5.4.
|
|
66
|
+
vike: "^0.4.191",
|
|
67
|
+
vite: "^5.4.2"
|
|
67
68
|
},
|
|
68
69
|
dependencies: {
|
|
69
70
|
"@batijs/core": "workspace:*"
|
|
@@ -132,7 +133,7 @@ async function getPackageJson(props) {
|
|
|
132
133
|
"hattip",
|
|
133
134
|
"vite",
|
|
134
135
|
"vike",
|
|
135
|
-
|
|
136
|
+
"@universal-middleware/hattip",
|
|
136
137
|
...props.meta.BATI.has("vercel") ? ["@hattip/adapter-vercel-edge"] : []
|
|
137
138
|
]
|
|
138
139
|
});
|
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
firebaseAuthMiddleware,
|
|
8
8
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
9
9
|
import {
|
|
10
|
+
luciaAuthContextMiddleware,
|
|
11
|
+
luciaAuthCookieMiddleware,
|
|
10
12
|
luciaAuthLoginHandler,
|
|
11
13
|
luciaAuthLogoutHandler,
|
|
12
|
-
luciaAuthMiddleware,
|
|
13
14
|
luciaAuthSignupHandler,
|
|
14
15
|
luciaCsrfMiddleware,
|
|
15
16
|
luciaGithubCallbackHandler,
|
|
@@ -21,23 +22,10 @@ import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
|
21
22
|
import { appRouter } from "@batijs/trpc/trpc/server";
|
|
22
23
|
import { tsRestHandler } from "@batijs/ts-rest/server/ts-rest-handler";
|
|
23
24
|
import type { HattipHandler } from "@hattip/core";
|
|
24
|
-
import { createRouter
|
|
25
|
+
import { createRouter } from "@hattip/router";
|
|
25
26
|
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
26
27
|
import vercelAdapter from "@hattip/adapter-vercel-edge";
|
|
27
|
-
|
|
28
|
-
interface Middleware<Context extends Record<string | number | symbol, unknown>> {
|
|
29
|
-
(request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function handlerAdapter<Context extends Record<string | number | symbol, unknown>>(
|
|
33
|
-
handler: Middleware<Context>,
|
|
34
|
-
): RouteHandler<unknown, unknown> {
|
|
35
|
-
return (context) => {
|
|
36
|
-
const rawContext = context as unknown as Record<string, unknown>;
|
|
37
|
-
rawContext.context ??= {};
|
|
38
|
-
return handler(context.request, rawContext.context as Context);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
28
|
+
import { createHandler, createMiddleware } from "@universal-middleware/hattip";
|
|
41
29
|
|
|
42
30
|
const router = createRouter();
|
|
43
31
|
|
|
@@ -47,7 +35,7 @@ if (BATI.has("telefunc")) {
|
|
|
47
35
|
*
|
|
48
36
|
* @link {@see https://telefunc.com}
|
|
49
37
|
**/
|
|
50
|
-
router.post("/_telefunc",
|
|
38
|
+
router.post("/_telefunc", createHandler(telefuncHandler)());
|
|
51
39
|
}
|
|
52
40
|
|
|
53
41
|
if (BATI.has("trpc")) {
|
|
@@ -69,41 +57,42 @@ if (BATI.has("trpc")) {
|
|
|
69
57
|
}
|
|
70
58
|
|
|
71
59
|
if (BATI.has("ts-rest")) {
|
|
72
|
-
router.use("/api/*",
|
|
60
|
+
router.use("/api/*", createMiddleware(tsRestHandler)());
|
|
73
61
|
}
|
|
74
62
|
|
|
75
63
|
if (BATI.has("authjs") || BATI.has("auth0")) {
|
|
76
64
|
/**
|
|
77
65
|
* Append Auth.js session to context
|
|
78
66
|
**/
|
|
79
|
-
router.use(
|
|
67
|
+
router.use(createMiddleware(authjsSessionMiddleware)());
|
|
80
68
|
|
|
81
69
|
/**
|
|
82
70
|
* Auth.js route
|
|
83
71
|
* @link {@see https://authjs.dev/getting-started/installation}
|
|
84
72
|
**/
|
|
85
|
-
router.use("/api/auth/*",
|
|
73
|
+
router.use("/api/auth/*", createHandler(authjsHandler)());
|
|
86
74
|
}
|
|
87
75
|
|
|
88
76
|
if (BATI.has("firebase-auth")) {
|
|
89
|
-
router.use(
|
|
90
|
-
router.post("/api/sessionLogin",
|
|
91
|
-
router.post("/api/sessionLogout",
|
|
77
|
+
router.use(createMiddleware(firebaseAuthMiddleware)());
|
|
78
|
+
router.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler)());
|
|
79
|
+
router.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler)());
|
|
92
80
|
}
|
|
93
81
|
|
|
94
82
|
if (BATI.has("lucia-auth")) {
|
|
95
|
-
router.use(
|
|
96
|
-
router.use(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
router.post("/api/
|
|
100
|
-
router.post("/api/
|
|
101
|
-
router.
|
|
102
|
-
router.get("/api/login/github
|
|
83
|
+
router.use(createMiddleware(luciaCsrfMiddleware)());
|
|
84
|
+
router.use(createMiddleware(luciaAuthContextMiddleware)());
|
|
85
|
+
router.use(createMiddleware(luciaAuthCookieMiddleware)());
|
|
86
|
+
|
|
87
|
+
router.post("/api/signup", createHandler(luciaAuthSignupHandler)());
|
|
88
|
+
router.post("/api/login", createHandler(luciaAuthLoginHandler)());
|
|
89
|
+
router.post("/api/logout", createHandler(luciaAuthLogoutHandler)());
|
|
90
|
+
router.get("/api/login/github", createHandler(luciaGithubLoginHandler)());
|
|
91
|
+
router.get("/api/login/github/callback", createHandler(luciaGithubCallbackHandler)());
|
|
103
92
|
}
|
|
104
93
|
|
|
105
94
|
if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
106
|
-
router.post("/api/todo/create",
|
|
95
|
+
router.post("/api/todo/create", createHandler(createTodoHandler)());
|
|
107
96
|
}
|
|
108
97
|
|
|
109
98
|
/**
|
|
@@ -111,7 +100,7 @@ if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
|
111
100
|
*
|
|
112
101
|
* @link {@see https://vike.dev}
|
|
113
102
|
**/
|
|
114
|
-
router.use(
|
|
103
|
+
router.use(createHandler(vikeHandler)());
|
|
115
104
|
|
|
116
105
|
const handler: HattipHandler = router.buildHandler();
|
|
117
106
|
|
|
@@ -51,18 +51,18 @@ var require_package = __commonJS({
|
|
|
51
51
|
"@batijs/telefunc": "workspace:^",
|
|
52
52
|
"@batijs/trpc": "workspace:^",
|
|
53
53
|
"@batijs/ts-rest": "workspace:*",
|
|
54
|
-
"@hono/node-server": "^1.12.
|
|
54
|
+
"@hono/node-server": "^1.12.1",
|
|
55
55
|
"@hono/vite-dev-server": "^0.14.0",
|
|
56
56
|
"@trpc/server": "^10.45.2",
|
|
57
57
|
"@types/node": "^18.19.14",
|
|
58
|
-
"@universal-middleware/hono": "^0.
|
|
58
|
+
"@universal-middleware/hono": "^0.2.1",
|
|
59
59
|
"cross-env": "^7.0.3",
|
|
60
60
|
dotenv: "^16.4.5",
|
|
61
|
-
hono: "^4.5.
|
|
61
|
+
hono: "^4.5.6",
|
|
62
62
|
telefunc: "^0.1.76",
|
|
63
63
|
tsx: "^4.17.0",
|
|
64
|
-
vike: "^0.4.
|
|
65
|
-
vite: "^5.4.
|
|
64
|
+
vike: "^0.4.191",
|
|
65
|
+
vite: "^5.4.2"
|
|
66
66
|
},
|
|
67
67
|
dependencies: {
|
|
68
68
|
"@batijs/core": "workspace:*"
|
|
@@ -119,16 +119,7 @@ async function getPackageJson(props) {
|
|
|
119
119
|
});
|
|
120
120
|
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
|
|
121
121
|
devDependencies: ["@hono/vite-dev-server", "@types/node"],
|
|
122
|
-
dependencies: [
|
|
123
|
-
"@hono/node-server",
|
|
124
|
-
"@universal-middleware/hono",
|
|
125
|
-
"cross-env",
|
|
126
|
-
"hono",
|
|
127
|
-
"tsx",
|
|
128
|
-
"vite",
|
|
129
|
-
"vike",
|
|
130
|
-
...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core", "dotenv"] : []
|
|
131
|
-
]
|
|
122
|
+
dependencies: ["@hono/node-server", "@universal-middleware/hono", "cross-env", "hono", "tsx", "vite", "vike"]
|
|
132
123
|
});
|
|
133
124
|
}
|
|
134
125
|
export {
|
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
firebaseAuthMiddleware,
|
|
8
8
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
9
9
|
import {
|
|
10
|
+
luciaAuthContextMiddleware,
|
|
11
|
+
luciaAuthCookieMiddleware,
|
|
10
12
|
luciaAuthLoginHandler,
|
|
11
13
|
luciaAuthLogoutHandler,
|
|
12
|
-
luciaAuthMiddleware,
|
|
13
14
|
luciaAuthSignupHandler,
|
|
14
15
|
luciaCsrfMiddleware,
|
|
15
16
|
luciaGithubCallbackHandler,
|
|
@@ -31,30 +32,31 @@ if (BATI.has("authjs") || BATI.has("auth0")) {
|
|
|
31
32
|
/**
|
|
32
33
|
* Append Auth.js session to context
|
|
33
34
|
**/
|
|
34
|
-
app.use(createMiddleware(authjsSessionMiddleware));
|
|
35
|
+
app.use(createMiddleware(authjsSessionMiddleware)());
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Auth.js route
|
|
38
39
|
* @link {@see https://authjs.dev/getting-started/installation}
|
|
39
40
|
**/
|
|
40
|
-
app.use("/api/auth/**", createHandler(authjsHandler));
|
|
41
|
+
app.use("/api/auth/**", createHandler(authjsHandler)());
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
if (BATI.has("firebase-auth")) {
|
|
44
|
-
app.use(createMiddleware(firebaseAuthMiddleware));
|
|
45
|
-
app.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler));
|
|
46
|
-
app.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler));
|
|
45
|
+
app.use(createMiddleware(firebaseAuthMiddleware)());
|
|
46
|
+
app.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler)());
|
|
47
|
+
app.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler)());
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
if (BATI.has("lucia-auth")) {
|
|
50
|
-
app.use(createMiddleware(luciaCsrfMiddleware));
|
|
51
|
-
app.use(createMiddleware(
|
|
51
|
+
app.use(createMiddleware(luciaCsrfMiddleware)());
|
|
52
|
+
app.use(createMiddleware(luciaAuthContextMiddleware)());
|
|
53
|
+
app.use(createMiddleware(luciaAuthCookieMiddleware)());
|
|
52
54
|
|
|
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));
|
|
55
|
+
app.post("/api/signup", createHandler(luciaAuthSignupHandler)());
|
|
56
|
+
app.post("/api/login", createHandler(luciaAuthLoginHandler)());
|
|
57
|
+
app.post("/api/logout", createHandler(luciaAuthLogoutHandler)());
|
|
58
|
+
app.get("/api/login/github", createHandler(luciaGithubLoginHandler)());
|
|
59
|
+
app.get("/api/login/github/callback", createHandler(luciaGithubCallbackHandler)());
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
if (BATI.has("trpc")) {
|
|
@@ -81,15 +83,15 @@ if (BATI.has("telefunc")) {
|
|
|
81
83
|
*
|
|
82
84
|
* @link {@see https://telefunc.com}
|
|
83
85
|
**/
|
|
84
|
-
app.post("/_telefunc", createHandler(telefuncHandler));
|
|
86
|
+
app.post("/_telefunc", createHandler(telefuncHandler)());
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
if (BATI.has("ts-rest")) {
|
|
88
|
-
app.all("/api/*", createHandler(tsRestHandler));
|
|
90
|
+
app.all("/api/*", createHandler(tsRestHandler)());
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
92
|
-
app.post("/api/todo/create", createHandler(createTodoHandler));
|
|
94
|
+
app.post("/api/todo/create", createHandler(createTodoHandler)());
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
/**
|
|
@@ -97,7 +99,7 @@ if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
|
97
99
|
*
|
|
98
100
|
* @link {@see https://vike.dev}
|
|
99
101
|
**/
|
|
100
|
-
app.all("*", createHandler(vikeHandler));
|
|
102
|
+
app.all("*", createHandler(vikeHandler)());
|
|
101
103
|
|
|
102
104
|
//# BATI.has("vercel")
|
|
103
105
|
export const GET = handle(app);
|
|
@@ -48,14 +48,15 @@ var require_package = __commonJS({
|
|
|
48
48
|
"@types/better-sqlite3": "^7.6.11",
|
|
49
49
|
"@types/cookie": "^0.6.0",
|
|
50
50
|
"@types/node": "^18.19.14",
|
|
51
|
+
"@universal-middleware/core": "^0.2.3",
|
|
51
52
|
arctic: "^1.9.2",
|
|
52
53
|
"better-sqlite3": "^11.1.2",
|
|
53
54
|
cookie: "^0.6.0",
|
|
54
55
|
dotenv: "^16.4.5",
|
|
55
56
|
"drizzle-orm": "^0.33.0",
|
|
56
57
|
lucia: "^3.2.0",
|
|
57
|
-
vike: "^0.4.
|
|
58
|
-
vite: "^5.4.
|
|
58
|
+
vike: "^0.4.191",
|
|
59
|
+
vite: "^5.4.2"
|
|
59
60
|
},
|
|
60
61
|
dependencies: {
|
|
61
62
|
"@batijs/core": "workspace:*"
|
|
@@ -124,6 +125,7 @@ async function getPackageJson(props) {
|
|
|
124
125
|
"arctic",
|
|
125
126
|
"cookie",
|
|
126
127
|
"lucia",
|
|
128
|
+
"@universal-middleware/core",
|
|
127
129
|
...props.meta.BATI.has("drizzle") ? ["@lucia-auth/adapter-drizzle"] : ["better-sqlite3", "@lucia-auth/adapter-sqlite"]
|
|
128
130
|
]
|
|
129
131
|
});
|
|
@@ -9,16 +9,14 @@ import { parse, serialize } from "cookie";
|
|
|
9
9
|
import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
|
|
10
10
|
import { oauthAccountTable, userTable } from "../database/schema/auth";
|
|
11
11
|
import { getExistingAccount, getExistingUser, validateInput } from "../database/auth-actions";
|
|
12
|
+
import type { Get, UniversalHandler, UniversalMiddleware } from "@universal-middleware/core";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* CSRF protection middleware
|
|
15
16
|
*
|
|
16
17
|
* @link {@see https://lucia-auth.com/guides/validate-session-cookies/}
|
|
17
18
|
*/
|
|
18
|
-
export
|
|
19
|
-
request: Request,
|
|
20
|
-
_context?: Context,
|
|
21
|
-
): Response | undefined {
|
|
19
|
+
export const luciaCsrfMiddleware = (() => async (request) => {
|
|
22
20
|
if (request.method === "GET") {
|
|
23
21
|
return;
|
|
24
22
|
}
|
|
@@ -32,46 +30,56 @@ export function luciaCsrfMiddleware<Context extends Record<string | number | sym
|
|
|
32
30
|
});
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
|
-
}
|
|
33
|
+
}) satisfies Get<[], UniversalMiddleware>;
|
|
36
34
|
|
|
37
35
|
/**
|
|
38
|
-
* Validate session cookies middleware
|
|
36
|
+
* Validate session cookies middleware and set context
|
|
39
37
|
*
|
|
40
38
|
* @link {@see https://lucia-auth.com/guides/validate-session-cookies/}
|
|
41
39
|
*/
|
|
42
|
-
export
|
|
43
|
-
request: Request,
|
|
44
|
-
context: Context & { session?: Session | null; user?: User | null },
|
|
45
|
-
): Promise<void> {
|
|
40
|
+
export const luciaAuthContextMiddleware = (() => async (request, context) => {
|
|
46
41
|
const sessionId = lucia.readSessionCookie(request.headers.get("cookie") ?? "");
|
|
47
42
|
|
|
48
43
|
if (!sessionId) {
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
return {
|
|
45
|
+
...context,
|
|
46
|
+
session: null,
|
|
47
|
+
user: null,
|
|
48
|
+
};
|
|
51
49
|
} else {
|
|
52
50
|
const { session, user } = await lucia.validateSession(sessionId);
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
return {
|
|
53
|
+
...context,
|
|
54
|
+
sessionId,
|
|
55
|
+
session,
|
|
56
|
+
user,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}) satisfies Get<[], UniversalMiddleware>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Set Set-Cookie headers if in context
|
|
63
|
+
*/
|
|
64
|
+
export const luciaAuthCookieMiddleware = (() => (_request, context) => {
|
|
65
|
+
return (response: Response) => {
|
|
66
|
+
if (context.session?.fresh) {
|
|
67
|
+
response.headers.append("Set-Cookie", lucia.createSessionCookie(context.session.id).serialize());
|
|
56
68
|
}
|
|
57
|
-
if (!session) {
|
|
58
|
-
|
|
69
|
+
if (context.sessionId && !context.session) {
|
|
70
|
+
response.headers.append("Set-Cookie", lucia.createBlankSessionCookie().serialize());
|
|
59
71
|
}
|
|
60
72
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
73
|
+
return response;
|
|
74
|
+
};
|
|
75
|
+
}) satisfies Get<[], UniversalMiddleware<{ session?: Session | null; user?: User | null; sessionId?: string | null }>>;
|
|
65
76
|
|
|
66
77
|
/**
|
|
67
78
|
* Register user handler
|
|
68
79
|
*
|
|
69
80
|
* @link {@see https://lucia-auth.com/guides/email-and-password/basics#register-user}
|
|
70
81
|
*/
|
|
71
|
-
export
|
|
72
|
-
request: Request,
|
|
73
|
-
_context?: Context,
|
|
74
|
-
): Promise<Response> {
|
|
82
|
+
export const luciaAuthSignupHandler = (() => async (request) => {
|
|
75
83
|
const body = (await request.json()) as { username: string; password: string };
|
|
76
84
|
const username = body.username ?? "";
|
|
77
85
|
const password = body.password ?? "";
|
|
@@ -134,17 +142,14 @@ export async function luciaAuthSignupHandler<Context extends Record<string | num
|
|
|
134
142
|
},
|
|
135
143
|
});
|
|
136
144
|
}
|
|
137
|
-
}
|
|
145
|
+
}) satisfies Get<[], UniversalMiddleware>;
|
|
138
146
|
|
|
139
147
|
/**
|
|
140
148
|
* Sign in user handler
|
|
141
149
|
*
|
|
142
150
|
* @link {@see https://lucia-auth.com/guides/email-and-password/basics#sign-in-user}
|
|
143
151
|
*/
|
|
144
|
-
export
|
|
145
|
-
request: Request,
|
|
146
|
-
_context?: Context,
|
|
147
|
-
): Promise<Response> {
|
|
152
|
+
export const luciaAuthLoginHandler = (() => async (request) => {
|
|
148
153
|
const body = (await request.json()) as { username: string; password: string };
|
|
149
154
|
const username = body.username ?? "";
|
|
150
155
|
const password = body.password ?? "";
|
|
@@ -191,15 +196,12 @@ export async function luciaAuthLoginHandler<Context extends Record<string | numb
|
|
|
191
196
|
"set-cookie": lucia.createSessionCookie(session.id).serialize(),
|
|
192
197
|
},
|
|
193
198
|
});
|
|
194
|
-
}
|
|
199
|
+
}) satisfies Get<[], UniversalMiddleware>;
|
|
195
200
|
|
|
196
201
|
/**
|
|
197
202
|
* Log out user handler
|
|
198
203
|
*/
|
|
199
|
-
export
|
|
200
|
-
_request: Request,
|
|
201
|
-
context: Context & { session?: Session | null },
|
|
202
|
-
): Promise<Response> {
|
|
204
|
+
export const luciaAuthLogoutHandler = (() => async (_request, context) => {
|
|
203
205
|
const session = context.session ?? null;
|
|
204
206
|
|
|
205
207
|
if (!session) {
|
|
@@ -225,17 +227,14 @@ export async function luciaAuthLogoutHandler<Context extends Record<string | num
|
|
|
225
227
|
"set-cookie": lucia.createBlankSessionCookie().serialize(),
|
|
226
228
|
},
|
|
227
229
|
});
|
|
228
|
-
}
|
|
230
|
+
}) satisfies Get<[], UniversalMiddleware<{ session?: Session | null }>>;
|
|
229
231
|
|
|
230
232
|
/**
|
|
231
233
|
* Github OAuth authorization handler
|
|
232
234
|
*
|
|
233
235
|
* @link {@see https://lucia-auth.com/guides/oauth/basics#creating-authorization-url}
|
|
234
236
|
*/
|
|
235
|
-
export
|
|
236
|
-
_request: Request,
|
|
237
|
-
_context?: Context,
|
|
238
|
-
): Promise<Response> {
|
|
237
|
+
export const luciaGithubLoginHandler = (() => async () => {
|
|
239
238
|
const state = generateState();
|
|
240
239
|
const url = await github.createAuthorizationURL(state);
|
|
241
240
|
|
|
@@ -252,17 +251,14 @@ export async function luciaGithubLoginHandler<Context extends Record<string | nu
|
|
|
252
251
|
}),
|
|
253
252
|
},
|
|
254
253
|
});
|
|
255
|
-
}
|
|
254
|
+
}) satisfies Get<[], UniversalHandler>;
|
|
256
255
|
|
|
257
256
|
/**
|
|
258
257
|
* Github OAuth validate callback handler
|
|
259
258
|
*
|
|
260
259
|
* @link {@see https://lucia-auth.com/guides/oauth/basics#validate-callback}
|
|
261
260
|
*/
|
|
262
|
-
export
|
|
263
|
-
request: Request,
|
|
264
|
-
_context?: Context,
|
|
265
|
-
): Promise<Response> {
|
|
261
|
+
export const luciaGithubCallbackHandler = (() => async (request) => {
|
|
266
262
|
const cookies = parse(request.headers.get("cookie") ?? "");
|
|
267
263
|
const params = new URL(request.url).searchParams;
|
|
268
264
|
const code = params.get("code");
|
|
@@ -341,4 +337,4 @@ export async function luciaGithubCallbackHandler<Context extends Record<string |
|
|
|
341
337
|
},
|
|
342
338
|
});
|
|
343
339
|
}
|
|
344
|
-
}
|
|
340
|
+
}) satisfies Get<[], UniversalHandler>;
|