@batijs/cli 0.0.243 → 0.0.245
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/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/eslint/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/express/files/$package.json.js +4 -4
- package/dist/boilerplates/@batijs/express/files/express-entry.ts +31 -9
- package/dist/boilerplates/@batijs/fastify/files/$package.json.js +6 -6
- package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +33 -45
- 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 +5 -2
- package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +33 -24
- package/dist/boilerplates/@batijs/h3/types/h3-entry.d.ts +0 -4
- package/dist/boilerplates/@batijs/hattip/files/$package.json.js +5 -3
- package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +33 -24
- package/dist/boilerplates/@batijs/hono/files/$package.json.js +7 -15
- package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +31 -9
- 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 +135 -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 +340 -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 +58 -0
- package/dist/boilerplates/@batijs/react/files/$package.json.js +4 -4
- 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/files/package.json +2 -2
- package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +103 -0
- package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +6 -8
- 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/shared-todo/files/pages/todo/+data.ts +3 -3
- package/dist/boilerplates/@batijs/solid/files/$package.json.js +5 -5
- 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/tailwindcss/files/$package.json.js +3 -3
- package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +4 -3
- package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +3 -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/trpc/files/trpc/server.ts +3 -3
- package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +4 -3
- package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +6 -9
- 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/files/layouts/LayoutDefault.vue +2 -0
- package/dist/boilerplates/@batijs/vue/files/pages/+config.ts +1 -1
- package/dist/boilerplates/@batijs/vue/types/pages/+config.d.ts +6 -0
- package/dist/boilerplates/@batijs/vue-lucia-auth/files/pages/login/+Page.vue +87 -0
- package/dist/boilerplates/boilerplates.json +59 -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
- 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
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { parse, serialize } from "cookie";
|
|
2
2
|
import { getAuth } from "firebase-admin/auth";
|
|
3
3
|
import { firebaseAdmin } from "../libs/firebaseAdmin";
|
|
4
|
+
import type { Get, UniversalHandler, UniversalMiddleware } from "@universal-middleware/core";
|
|
4
5
|
|
|
5
|
-
export async
|
|
6
|
-
request: Request,
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
-
context: any,
|
|
9
|
-
): Promise<void> {
|
|
6
|
+
export const firebaseAuthMiddleware = (() => async (request, context) => {
|
|
10
7
|
if (!request.headers.has("cookie")) return;
|
|
11
8
|
|
|
12
9
|
const cookies = parse(request.headers.get("cookie")!);
|
|
@@ -15,17 +12,21 @@ export async function firebaseAuthMiddleware(
|
|
|
15
12
|
try {
|
|
16
13
|
const auth = getAuth(firebaseAdmin);
|
|
17
14
|
const decodedIdToken = await auth.verifySessionCookie(sessionCookie, true);
|
|
18
|
-
|
|
15
|
+
const user = await auth.getUser(decodedIdToken.sub);
|
|
16
|
+
return {
|
|
17
|
+
...context,
|
|
18
|
+
user,
|
|
19
|
+
};
|
|
19
20
|
} catch (error) {
|
|
20
21
|
console.debug("verifySessionCookie:", error);
|
|
21
|
-
|
|
22
|
+
return {
|
|
23
|
+
...context,
|
|
24
|
+
user: null,
|
|
25
|
+
};
|
|
22
26
|
}
|
|
23
|
-
}
|
|
27
|
+
}) satisfies Get<[], UniversalMiddleware>;
|
|
24
28
|
|
|
25
|
-
export
|
|
26
|
-
request: Request,
|
|
27
|
-
_context?: Context,
|
|
28
|
-
): Promise<Response> {
|
|
29
|
+
export const firebaseAuthLoginHandler: Get<[], UniversalHandler> = () => async (request) => {
|
|
29
30
|
const body = await request.json();
|
|
30
31
|
const idToken: string = (body as { idToken?: string }).idToken || "";
|
|
31
32
|
|
|
@@ -50,12 +51,9 @@ export async function firebaseAuthLoginHandler<Context extends Record<string | n
|
|
|
50
51
|
status: 401,
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
|
-
}
|
|
54
|
+
};
|
|
54
55
|
|
|
55
|
-
export
|
|
56
|
-
_request: Request,
|
|
57
|
-
_context?: Context,
|
|
58
|
-
): Promise<Response> {
|
|
56
|
+
export const firebaseAuthLogoutHandler: Get<[], UniversalHandler> = () => async () => {
|
|
59
57
|
return new Response(JSON.stringify({ status: "success" }), {
|
|
60
58
|
status: 200,
|
|
61
59
|
headers: {
|
|
@@ -69,4 +67,4 @@ export async function firebaseAuthLogoutHandler<Context extends Record<string |
|
|
|
69
67
|
}),
|
|
70
68
|
},
|
|
71
69
|
});
|
|
72
|
-
}
|
|
70
|
+
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export declare
|
|
3
|
-
|
|
1
|
+
import type { Get, UniversalHandler } from "@universal-middleware/core";
|
|
2
|
+
export declare const firebaseAuthMiddleware: () => (request: Request, context: Universal.Context) => Promise<{
|
|
3
|
+
user: import("firebase-admin/auth").UserRecord;
|
|
4
|
+
} | {
|
|
5
|
+
user: null;
|
|
6
|
+
} | undefined>;
|
|
7
|
+
export declare const firebaseAuthLoginHandler: Get<[], UniversalHandler>;
|
|
8
|
+
export declare const firebaseAuthLogoutHandler: Get<[], UniversalHandler>;
|
|
@@ -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:^",
|
|
@@ -55,14 +56,15 @@ var require_package = __commonJS({
|
|
|
55
56
|
"@types/express": "^4.17.21",
|
|
56
57
|
"@types/node": "^18.19.14",
|
|
57
58
|
"@types/serve-static": "^1.15.7",
|
|
59
|
+
"@universal-middleware/h3": "^0.2.0",
|
|
58
60
|
"cross-env": "^7.0.3",
|
|
59
61
|
dotenv: "^16.4.5",
|
|
60
62
|
h3: "~1.12.0",
|
|
61
63
|
"serve-static": "^1.15.0",
|
|
62
64
|
telefunc: "^0.1.76",
|
|
63
65
|
tsx: "^4.17.0",
|
|
64
|
-
vike: "^0.4.
|
|
65
|
-
vite: "^5.4.
|
|
66
|
+
vike: "^0.4.187",
|
|
67
|
+
vite: "^5.4.1"
|
|
66
68
|
},
|
|
67
69
|
dependencies: {
|
|
68
70
|
"@batijs/core": "workspace:*"
|
|
@@ -124,6 +126,7 @@ async function getPackageJson(props) {
|
|
|
124
126
|
"tsx",
|
|
125
127
|
"vike",
|
|
126
128
|
"vite",
|
|
129
|
+
"@universal-middleware/h3",
|
|
127
130
|
...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core"] : []
|
|
128
131
|
]
|
|
129
132
|
});
|
|
@@ -9,6 +9,16 @@ import {
|
|
|
9
9
|
firebaseAuthLogoutHandler,
|
|
10
10
|
firebaseAuthMiddleware,
|
|
11
11
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
12
|
+
import {
|
|
13
|
+
luciaAuthContextMiddleware,
|
|
14
|
+
luciaAuthCookieMiddleware,
|
|
15
|
+
luciaAuthLoginHandler,
|
|
16
|
+
luciaAuthLogoutHandler,
|
|
17
|
+
luciaAuthSignupHandler,
|
|
18
|
+
luciaCsrfMiddleware,
|
|
19
|
+
luciaGithubCallbackHandler,
|
|
20
|
+
luciaGithubLoginHandler,
|
|
21
|
+
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
12
22
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
13
23
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
14
24
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
@@ -18,8 +28,9 @@ import installCrypto from "@hattip/polyfills/crypto";
|
|
|
18
28
|
import installGetSetCookie from "@hattip/polyfills/get-set-cookie";
|
|
19
29
|
import installWhatwgNodeFetch from "@hattip/polyfills/whatwg-node";
|
|
20
30
|
import { type NodeHTTPCreateContextFnOptions, nodeHTTPRequestHandler } from "@trpc/server/adapters/node-http";
|
|
21
|
-
import { createApp, createRouter, eventHandler, fromNodeMiddleware, toNodeListener
|
|
31
|
+
import { createApp, createRouter, eventHandler, fromNodeMiddleware, toNodeListener } from "h3";
|
|
22
32
|
import serveStatic from "serve-static";
|
|
33
|
+
import { createHandler, createMiddleware } from "@universal-middleware/h3";
|
|
23
34
|
|
|
24
35
|
installWhatwgNodeFetch();
|
|
25
36
|
installGetSetCookie();
|
|
@@ -31,20 +42,6 @@ const root = __dirname;
|
|
|
31
42
|
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
32
43
|
const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678;
|
|
33
44
|
|
|
34
|
-
interface Middleware<Context extends Record<string | number | symbol, unknown>> {
|
|
35
|
-
(request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function fromWebMiddleware<Context extends Record<string | number | symbol, unknown>>(
|
|
39
|
-
handler: Middleware<Context>,
|
|
40
|
-
) {
|
|
41
|
-
return eventHandler((event) => {
|
|
42
|
-
const ctx = event.context as unknown as Record<string, unknown>;
|
|
43
|
-
ctx.context ??= {};
|
|
44
|
-
return handler(toWebRequest(event), ctx.context as Context);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
45
|
export default await startServer();
|
|
49
46
|
|
|
50
47
|
async function startServer() {
|
|
@@ -72,19 +69,31 @@ async function startServer() {
|
|
|
72
69
|
/**
|
|
73
70
|
* Append Auth.js session to context
|
|
74
71
|
**/
|
|
75
|
-
app.use(
|
|
72
|
+
app.use(createMiddleware(authjsSessionMiddleware)());
|
|
76
73
|
|
|
77
74
|
/**
|
|
78
75
|
* Auth.js route
|
|
79
76
|
* @link {@see https://authjs.dev/getting-started/installation}
|
|
80
77
|
**/
|
|
81
|
-
router.use("/api/auth/**",
|
|
78
|
+
router.use("/api/auth/**", createHandler(authjsHandler)());
|
|
82
79
|
}
|
|
83
80
|
|
|
84
81
|
if (BATI.has("firebase-auth")) {
|
|
85
|
-
app.use(
|
|
86
|
-
router.post("/api/sessionLogin",
|
|
87
|
-
router.post("/api/sessionLogout",
|
|
82
|
+
app.use(createMiddleware(firebaseAuthMiddleware)());
|
|
83
|
+
router.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler)());
|
|
84
|
+
router.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler)());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (BATI.has("lucia-auth")) {
|
|
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)());
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
if (BATI.has("trpc")) {
|
|
@@ -115,15 +124,15 @@ async function startServer() {
|
|
|
115
124
|
*
|
|
116
125
|
* @link {@see https://telefunc.com}
|
|
117
126
|
**/
|
|
118
|
-
router.post("/_telefunc",
|
|
127
|
+
router.post("/_telefunc", createHandler(telefuncHandler)());
|
|
119
128
|
}
|
|
120
129
|
|
|
121
130
|
if (BATI.has("ts-rest")) {
|
|
122
|
-
router.use("/api/**",
|
|
131
|
+
router.use("/api/**", createHandler(tsRestHandler)());
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
126
|
-
router.post("/api/todo/create",
|
|
135
|
+
router.post("/api/todo/create", createHandler(createTodoHandler)());
|
|
127
136
|
}
|
|
128
137
|
|
|
129
138
|
/**
|
|
@@ -131,7 +140,7 @@ async function startServer() {
|
|
|
131
140
|
*
|
|
132
141
|
* @link {@see https://vike.dev}
|
|
133
142
|
**/
|
|
134
|
-
router.use("/**",
|
|
143
|
+
router.use("/**", createHandler(vikeHandler)());
|
|
135
144
|
|
|
136
145
|
app.use(router);
|
|
137
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;
|
|
@@ -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:^",
|
|
@@ -57,12 +58,13 @@ var require_package = __commonJS({
|
|
|
57
58
|
"@hattip/vite": "^0.0.47",
|
|
58
59
|
"@trpc/server": "^10.45.2",
|
|
59
60
|
"@types/node": "^18.19.14",
|
|
61
|
+
"@universal-middleware/hattip": "^0.2.1",
|
|
60
62
|
"cross-env": "^7.0.3",
|
|
61
63
|
dotenv: "^16.4.5",
|
|
62
64
|
hattip: "^0.0.33",
|
|
63
65
|
telefunc: "^0.1.76",
|
|
64
|
-
vike: "^0.4.
|
|
65
|
-
vite: "^5.4.
|
|
66
|
+
vike: "^0.4.187",
|
|
67
|
+
vite: "^5.4.1"
|
|
66
68
|
},
|
|
67
69
|
dependencies: {
|
|
68
70
|
"@batijs/core": "workspace:*"
|
|
@@ -131,7 +133,7 @@ async function getPackageJson(props) {
|
|
|
131
133
|
"hattip",
|
|
132
134
|
"vite",
|
|
133
135
|
"vike",
|
|
134
|
-
|
|
136
|
+
"@universal-middleware/hattip",
|
|
135
137
|
...props.meta.BATI.has("vercel") ? ["@hattip/adapter-vercel-edge"] : []
|
|
136
138
|
]
|
|
137
139
|
});
|
|
@@ -6,29 +6,26 @@ import {
|
|
|
6
6
|
firebaseAuthLogoutHandler,
|
|
7
7
|
firebaseAuthMiddleware,
|
|
8
8
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
9
|
+
import {
|
|
10
|
+
luciaAuthContextMiddleware,
|
|
11
|
+
luciaAuthCookieMiddleware,
|
|
12
|
+
luciaAuthLoginHandler,
|
|
13
|
+
luciaAuthLogoutHandler,
|
|
14
|
+
luciaAuthSignupHandler,
|
|
15
|
+
luciaCsrfMiddleware,
|
|
16
|
+
luciaGithubCallbackHandler,
|
|
17
|
+
luciaGithubLoginHandler,
|
|
18
|
+
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
9
19
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
10
20
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
11
21
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
12
22
|
import { appRouter } from "@batijs/trpc/trpc/server";
|
|
13
23
|
import { tsRestHandler } from "@batijs/ts-rest/server/ts-rest-handler";
|
|
14
24
|
import type { HattipHandler } from "@hattip/core";
|
|
15
|
-
import { createRouter
|
|
25
|
+
import { createRouter } from "@hattip/router";
|
|
16
26
|
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
17
27
|
import vercelAdapter from "@hattip/adapter-vercel-edge";
|
|
18
|
-
|
|
19
|
-
interface Middleware<Context extends Record<string | number | symbol, unknown>> {
|
|
20
|
-
(request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function handlerAdapter<Context extends Record<string | number | symbol, unknown>>(
|
|
24
|
-
handler: Middleware<Context>,
|
|
25
|
-
): RouteHandler<unknown, unknown> {
|
|
26
|
-
return (context) => {
|
|
27
|
-
const rawContext = context as unknown as Record<string, unknown>;
|
|
28
|
-
rawContext.context ??= {};
|
|
29
|
-
return handler(context.request, rawContext.context as Context);
|
|
30
|
-
};
|
|
31
|
-
}
|
|
28
|
+
import { createHandler, createMiddleware } from "@universal-middleware/hattip";
|
|
32
29
|
|
|
33
30
|
const router = createRouter();
|
|
34
31
|
|
|
@@ -38,7 +35,7 @@ if (BATI.has("telefunc")) {
|
|
|
38
35
|
*
|
|
39
36
|
* @link {@see https://telefunc.com}
|
|
40
37
|
**/
|
|
41
|
-
router.post("/_telefunc",
|
|
38
|
+
router.post("/_telefunc", createHandler(telefuncHandler)());
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
if (BATI.has("trpc")) {
|
|
@@ -60,30 +57,42 @@ if (BATI.has("trpc")) {
|
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
if (BATI.has("ts-rest")) {
|
|
63
|
-
router.use("/api/*",
|
|
60
|
+
router.use("/api/*", createMiddleware(tsRestHandler)());
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
if (BATI.has("authjs") || BATI.has("auth0")) {
|
|
67
64
|
/**
|
|
68
65
|
* Append Auth.js session to context
|
|
69
66
|
**/
|
|
70
|
-
router.use(
|
|
67
|
+
router.use(createMiddleware(authjsSessionMiddleware)());
|
|
71
68
|
|
|
72
69
|
/**
|
|
73
70
|
* Auth.js route
|
|
74
71
|
* @link {@see https://authjs.dev/getting-started/installation}
|
|
75
72
|
**/
|
|
76
|
-
router.use("/api/auth/*",
|
|
73
|
+
router.use("/api/auth/*", createHandler(authjsHandler)());
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
if (BATI.has("firebase-auth")) {
|
|
80
|
-
router.use(
|
|
81
|
-
router.post("/api/sessionLogin",
|
|
82
|
-
router.post("/api/sessionLogout",
|
|
77
|
+
router.use(createMiddleware(firebaseAuthMiddleware)());
|
|
78
|
+
router.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler)());
|
|
79
|
+
router.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler)());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (BATI.has("lucia-auth")) {
|
|
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)());
|
|
83
92
|
}
|
|
84
93
|
|
|
85
94
|
if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
86
|
-
router.post("/api/todo/create",
|
|
95
|
+
router.post("/api/todo/create", createHandler(createTodoHandler)());
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
/**
|
|
@@ -91,7 +100,7 @@ if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
|
91
100
|
*
|
|
92
101
|
* @link {@see https://vike.dev}
|
|
93
102
|
**/
|
|
94
|
-
router.use(
|
|
103
|
+
router.use(createHandler(vikeHandler)());
|
|
95
104
|
|
|
96
105
|
const handler: HattipHandler = router.buildHandler();
|
|
97
106
|
|
|
@@ -45,23 +45,24 @@ 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:^",
|
|
51
52
|
"@batijs/trpc": "workspace:^",
|
|
52
53
|
"@batijs/ts-rest": "workspace:*",
|
|
53
|
-
"@hono/node-server": "^1.12.
|
|
54
|
+
"@hono/node-server": "^1.12.1",
|
|
54
55
|
"@hono/vite-dev-server": "^0.14.0",
|
|
55
56
|
"@trpc/server": "^10.45.2",
|
|
56
57
|
"@types/node": "^18.19.14",
|
|
57
|
-
"@universal-middleware/hono": "^0.
|
|
58
|
+
"@universal-middleware/hono": "^0.2.1",
|
|
58
59
|
"cross-env": "^7.0.3",
|
|
59
60
|
dotenv: "^16.4.5",
|
|
60
|
-
hono: "^4.5.
|
|
61
|
+
hono: "^4.5.6",
|
|
61
62
|
telefunc: "^0.1.76",
|
|
62
63
|
tsx: "^4.17.0",
|
|
63
|
-
vike: "^0.4.
|
|
64
|
-
vite: "^5.4.
|
|
64
|
+
vike: "^0.4.187",
|
|
65
|
+
vite: "^5.4.1"
|
|
65
66
|
},
|
|
66
67
|
dependencies: {
|
|
67
68
|
"@batijs/core": "workspace:*"
|
|
@@ -118,16 +119,7 @@ async function getPackageJson(props) {
|
|
|
118
119
|
});
|
|
119
120
|
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
|
|
120
121
|
devDependencies: ["@hono/vite-dev-server", "@types/node"],
|
|
121
|
-
dependencies: [
|
|
122
|
-
"@hono/node-server",
|
|
123
|
-
"@universal-middleware/hono",
|
|
124
|
-
"cross-env",
|
|
125
|
-
"hono",
|
|
126
|
-
"tsx",
|
|
127
|
-
"vite",
|
|
128
|
-
"vike",
|
|
129
|
-
...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core", "dotenv"] : []
|
|
130
|
-
]
|
|
122
|
+
dependencies: ["@hono/node-server", "@universal-middleware/hono", "cross-env", "hono", "tsx", "vite", "vike"]
|
|
131
123
|
});
|
|
132
124
|
}
|
|
133
125
|
export {
|
|
@@ -6,6 +6,16 @@ import {
|
|
|
6
6
|
firebaseAuthLogoutHandler,
|
|
7
7
|
firebaseAuthMiddleware,
|
|
8
8
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
9
|
+
import {
|
|
10
|
+
luciaAuthContextMiddleware,
|
|
11
|
+
luciaAuthCookieMiddleware,
|
|
12
|
+
luciaAuthLoginHandler,
|
|
13
|
+
luciaAuthLogoutHandler,
|
|
14
|
+
luciaAuthSignupHandler,
|
|
15
|
+
luciaCsrfMiddleware,
|
|
16
|
+
luciaGithubCallbackHandler,
|
|
17
|
+
luciaGithubLoginHandler,
|
|
18
|
+
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
9
19
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
10
20
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
11
21
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
@@ -22,19 +32,31 @@ if (BATI.has("authjs") || BATI.has("auth0")) {
|
|
|
22
32
|
/**
|
|
23
33
|
* Append Auth.js session to context
|
|
24
34
|
**/
|
|
25
|
-
app.use(createMiddleware(authjsSessionMiddleware));
|
|
35
|
+
app.use(createMiddleware(authjsSessionMiddleware)());
|
|
26
36
|
|
|
27
37
|
/**
|
|
28
38
|
* Auth.js route
|
|
29
39
|
* @link {@see https://authjs.dev/getting-started/installation}
|
|
30
40
|
**/
|
|
31
|
-
app.use("/api/auth/**", createHandler(authjsHandler));
|
|
41
|
+
app.use("/api/auth/**", createHandler(authjsHandler)());
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
if (BATI.has("firebase-auth")) {
|
|
35
|
-
app.use(createMiddleware(firebaseAuthMiddleware));
|
|
36
|
-
app.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler));
|
|
37
|
-
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)());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (BATI.has("lucia-auth")) {
|
|
51
|
+
app.use(createMiddleware(luciaCsrfMiddleware)());
|
|
52
|
+
app.use(createMiddleware(luciaAuthContextMiddleware)());
|
|
53
|
+
app.use(createMiddleware(luciaAuthCookieMiddleware)());
|
|
54
|
+
|
|
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)());
|
|
38
60
|
}
|
|
39
61
|
|
|
40
62
|
if (BATI.has("trpc")) {
|
|
@@ -61,15 +83,15 @@ if (BATI.has("telefunc")) {
|
|
|
61
83
|
*
|
|
62
84
|
* @link {@see https://telefunc.com}
|
|
63
85
|
**/
|
|
64
|
-
app.post("/_telefunc", createHandler(telefuncHandler));
|
|
86
|
+
app.post("/_telefunc", createHandler(telefuncHandler)());
|
|
65
87
|
}
|
|
66
88
|
|
|
67
89
|
if (BATI.has("ts-rest")) {
|
|
68
|
-
app.all("/api/*", createHandler(tsRestHandler));
|
|
90
|
+
app.all("/api/*", createHandler(tsRestHandler)());
|
|
69
91
|
}
|
|
70
92
|
|
|
71
93
|
if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
72
|
-
app.post("/api/todo/create", createHandler(createTodoHandler));
|
|
94
|
+
app.post("/api/todo/create", createHandler(createTodoHandler)());
|
|
73
95
|
}
|
|
74
96
|
|
|
75
97
|
/**
|
|
@@ -77,7 +99,7 @@ if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
|
77
99
|
*
|
|
78
100
|
* @link {@see https://vike.dev}
|
|
79
101
|
**/
|
|
80
|
-
app.all("*", createHandler(vikeHandler));
|
|
102
|
+
app.all("*", createHandler(vikeHandler)());
|
|
81
103
|
|
|
82
104
|
//# BATI.has("vercel")
|
|
83
105
|
export const GET = handle(app);
|
|
@@ -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
|
+
};
|