@batijs/cli 0.0.194 → 0.0.196
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/auth0/files/$.env.js +5 -9
- package/dist/boilerplates/@batijs/auth0/files/$README.md.js +8 -17
- package/dist/boilerplates/@batijs/authjs/files/server/authjs-handler.ts +100 -0
- package/dist/boilerplates/@batijs/authjs/types/server/authjs-handler.d.ts +16 -0
- package/dist/boilerplates/@batijs/edgedb/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/eslint/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/eslint/files/.eslintrc.json +15 -2
- package/dist/boilerplates/@batijs/express/files/$package.json.js +10 -11
- package/dist/boilerplates/@batijs/express/files/express-entry.ts +51 -144
- package/dist/boilerplates/@batijs/express/types/express-entry.d.ts +5 -0
- package/dist/boilerplates/@batijs/fastify/files/$package.json.js +8 -12
- package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +63 -149
- package/dist/boilerplates/@batijs/fastify/types/fastify-entry.d.ts +6 -0
- package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +11 -3
- package/dist/boilerplates/@batijs/firebase-auth/files/libs/firebaseAdmin.ts +2 -1
- package/dist/boilerplates/@batijs/firebase-auth/files/server/firebase-auth-middleware.ts +72 -0
- package/dist/boilerplates/@batijs/firebase-auth/types/libs/firebaseAdmin.d.ts +2 -1
- package/dist/boilerplates/@batijs/firebase-auth/types/server/firebase-auth-middleware.d.ts +4 -0
- package/dist/boilerplates/@batijs/h3/files/$package.json.js +6 -8
- package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +36 -175
- package/dist/boilerplates/@batijs/h3/types/h3-entry.d.ts +5 -0
- package/dist/boilerplates/@batijs/hattip/files/$package.json.js +8 -4
- package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +40 -60
- package/dist/boilerplates/@batijs/hattip/types/hattip-entry.d.ts +1 -0
- package/dist/boilerplates/@batijs/hono/files/$package.json.js +8 -6
- package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +54 -116
- package/dist/boilerplates/@batijs/hono/types/hono-entry.d.ts +5 -0
- package/dist/boilerplates/@batijs/react/files/$.eslintrc.json.js +0 -4
- package/dist/boilerplates/@batijs/react/files/$package.json.js +6 -6
- package/dist/boilerplates/@batijs/react-telefunc/files/pages/todo/TodoList.tsx +4 -4
- package/dist/boilerplates/@batijs/shared/files/package.json +2 -1
- package/dist/boilerplates/@batijs/shared-server/files/server/vike-handler.ts +15 -0
- package/dist/boilerplates/@batijs/shared-server/types/server/vike-handler.d.ts +2 -0
- package/dist/boilerplates/@batijs/solid/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/solid-telefunc/files/pages/todo/+Page.tsx +6 -3
- package/dist/boilerplates/@batijs/solid-telefunc/files/pages/todo/+data.ts +9 -0
- package/dist/boilerplates/@batijs/solid-telefunc/files/pages/todo/TodoList.tsx +4 -4
- package/dist/boilerplates/@batijs/solid-telefunc/types/pages/todo/+Page.d.ts +1 -4
- package/dist/boilerplates/@batijs/solid-telefunc/types/pages/todo/+data.d.ts +2 -0
- package/dist/boilerplates/@batijs/solid-trpc/files/pages/todo-trpc/+Page.tsx +6 -3
- package/dist/boilerplates/@batijs/solid-trpc/files/pages/todo-trpc/+data.ts +9 -0
- package/dist/boilerplates/@batijs/solid-trpc/files/pages/todo-trpc/TodoList.tsx +4 -4
- package/dist/boilerplates/@batijs/solid-trpc/types/pages/todo-trpc/+Page.d.ts +1 -4
- package/dist/boilerplates/@batijs/solid-trpc/types/pages/todo-trpc/+data.d.ts +2 -0
- package/dist/boilerplates/@batijs/tailwindcss/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +13 -1
- package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +20 -0
- package/dist/boilerplates/@batijs/telefunc/types/server/telefunc-handler.d.ts +2 -0
- package/dist/boilerplates/@batijs/vercel/files/$package.json.js +3 -3
- package/dist/boilerplates/@batijs/vue/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/vue-telefunc/files/components/TodoList.vue +6 -6
- package/dist/boilerplates/@batijs/vue-trpc/files/components/TodoListTrpc.vue +6 -6
- package/dist/boilerplates/boilerplates.json +35 -0
- package/dist/index.js +3 -6
- package/package.json +7 -7
- package/dist/boilerplates/@batijs/solid-telefunc/files/pages/todo/+onBeforeRender.ts +0 -15
- package/dist/boilerplates/@batijs/solid-telefunc/types/pages/todo/+onBeforeRender.d.ts +0 -8
- package/dist/boilerplates/@batijs/solid-trpc/files/pages/todo-trpc/+onBeforeRender.ts +0 -15
- package/dist/boilerplates/@batijs/solid-trpc/types/pages/todo-trpc/+onBeforeRender.d.ts +0 -8
|
@@ -3,36 +3,29 @@ import "dotenv/config";
|
|
|
3
3
|
import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
|
|
4
4
|
import { dirname } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
6
|
+
import { authjsHandler, authjsSessionMiddleware } from "@batijs/authjs/server/authjs-handler";
|
|
7
|
+
import {
|
|
8
|
+
firebaseAuthLoginHandler,
|
|
9
|
+
firebaseAuthLogoutHandler,
|
|
10
|
+
firebaseAuthMiddleware,
|
|
11
|
+
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
12
|
+
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
13
|
+
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
8
14
|
import { appRouter } from "@batijs/trpc/trpc/server";
|
|
9
15
|
import installCrypto from "@hattip/polyfills/crypto";
|
|
10
16
|
import installGetSetCookie from "@hattip/polyfills/get-set-cookie";
|
|
11
17
|
import installWhatwgNodeFetch from "@hattip/polyfills/whatwg-node";
|
|
12
18
|
import { nodeHTTPRequestHandler, type NodeHTTPCreateContextFnOptions } from "@trpc/server/adapters/node-http";
|
|
13
|
-
import express from "express";
|
|
14
|
-
import { auth, type ConfigParams } from "express-openid-connect";
|
|
15
|
-
import { getAuth } from "firebase-admin/auth";
|
|
16
19
|
import {
|
|
17
20
|
createApp,
|
|
18
21
|
createRouter,
|
|
19
|
-
deleteCookie,
|
|
20
22
|
eventHandler,
|
|
21
23
|
fromNodeMiddleware,
|
|
22
|
-
|
|
23
|
-
getResponseStatus,
|
|
24
|
-
getResponseStatusText,
|
|
25
|
-
readBody,
|
|
26
|
-
setCookie,
|
|
27
|
-
setResponseHeaders,
|
|
28
|
-
setResponseStatus,
|
|
24
|
+
fromWebHandler,
|
|
29
25
|
toNodeListener,
|
|
30
26
|
toWebRequest,
|
|
31
27
|
} from "h3";
|
|
32
28
|
import serveStatic from "serve-static";
|
|
33
|
-
import { telefunc } from "telefunc";
|
|
34
|
-
import { VikeAuth } from "vike-authjs";
|
|
35
|
-
import { renderPage } from "vike/server";
|
|
36
29
|
|
|
37
30
|
installWhatwgNodeFetch();
|
|
38
31
|
installGetSetCookie();
|
|
@@ -45,6 +38,20 @@ const root = __dirname;
|
|
|
45
38
|
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
46
39
|
const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678;
|
|
47
40
|
|
|
41
|
+
interface Middleware<Context extends Record<string | number | symbol, unknown>> {
|
|
42
|
+
(request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function fromWebMiddleware<Context extends Record<string | number | symbol, unknown>>(
|
|
46
|
+
handler: Middleware<Context>,
|
|
47
|
+
) {
|
|
48
|
+
return eventHandler((event) => {
|
|
49
|
+
const ctx = event.context as unknown as Record<string, unknown>;
|
|
50
|
+
ctx.context ??= {};
|
|
51
|
+
return handler(toWebRequest(event), ctx.context as Context);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
48
55
|
startServer();
|
|
49
56
|
|
|
50
57
|
async function startServer() {
|
|
@@ -68,127 +75,23 @@ async function startServer() {
|
|
|
68
75
|
|
|
69
76
|
const router = createRouter();
|
|
70
77
|
|
|
71
|
-
if (BATI.has("authjs")) {
|
|
78
|
+
if (BATI.has("authjs") || BATI.has("auth0")) {
|
|
72
79
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* TODO: Replace secret {@see https://authjs.dev/reference/core#secret}
|
|
76
|
-
* TODO: Choose and implement providers
|
|
77
|
-
*
|
|
78
|
-
* @link {@see https://authjs.dev/guides/providers/custom-provider}
|
|
80
|
+
* Append Auth.js session to context
|
|
79
81
|
**/
|
|
80
|
-
|
|
81
|
-
secret: "MY_SECRET",
|
|
82
|
-
providers: [
|
|
83
|
-
CredentialsProvider({
|
|
84
|
-
name: "Credentials",
|
|
85
|
-
credentials: {
|
|
86
|
-
username: { label: "Username", type: "text", placeholder: "jsmith" },
|
|
87
|
-
password: { label: "Password", type: "password" },
|
|
88
|
-
},
|
|
89
|
-
async authorize() {
|
|
90
|
-
// Add logic here to look up the user from the credentials supplied
|
|
91
|
-
const user = { id: "1", name: "J Smith", email: "jsmith@example.com" };
|
|
92
|
-
|
|
93
|
-
// Any object returned will be saved in `user` property of the JWT
|
|
94
|
-
// If you return null then an error will be displayed advising the user to check their details.
|
|
95
|
-
// You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
|
|
96
|
-
return user ?? null;
|
|
97
|
-
},
|
|
98
|
-
}),
|
|
99
|
-
],
|
|
100
|
-
});
|
|
82
|
+
app.use(fromWebMiddleware(authjsSessionMiddleware));
|
|
101
83
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}),
|
|
108
|
-
),
|
|
109
|
-
);
|
|
84
|
+
/**
|
|
85
|
+
* Auth.js route
|
|
86
|
+
* @link {@see https://authjs.dev/getting-started/installation}
|
|
87
|
+
**/
|
|
88
|
+
router.use("/api/auth/**", fromWebHandler(authjsHandler));
|
|
110
89
|
}
|
|
111
90
|
|
|
112
91
|
if (BATI.has("firebase-auth")) {
|
|
113
|
-
app.use(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (sessionCookie) {
|
|
117
|
-
try {
|
|
118
|
-
const auth = getAuth(firebaseAdmin);
|
|
119
|
-
const decodedIdToken = await auth.verifySessionCookie(sessionCookie);
|
|
120
|
-
const user = await auth.getUser(decodedIdToken.sub);
|
|
121
|
-
event.context.user = user;
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.debug("verifySessionCookie:", error);
|
|
124
|
-
event.context.user = null;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
router.post(
|
|
131
|
-
"/api/sessionLogin",
|
|
132
|
-
eventHandler(async (event) => {
|
|
133
|
-
const body = await readBody(event);
|
|
134
|
-
const idToken: string = body.idToken || "";
|
|
135
|
-
|
|
136
|
-
let status: number;
|
|
137
|
-
let text: string;
|
|
138
|
-
|
|
139
|
-
const expiresIn = 60 * 60 * 24 * 5 * 1000; // 5 days
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
const auth = getAuth(firebaseAdmin);
|
|
143
|
-
const sessionCookie = await auth.createSessionCookie(idToken, { expiresIn });
|
|
144
|
-
setCookie(event, "__session", sessionCookie, {
|
|
145
|
-
maxAge: expiresIn,
|
|
146
|
-
httpOnly: true,
|
|
147
|
-
secure: true,
|
|
148
|
-
});
|
|
149
|
-
setResponseStatus(event, 200, "Success");
|
|
150
|
-
|
|
151
|
-
status = getResponseStatus(event);
|
|
152
|
-
text = getResponseStatusText(event);
|
|
153
|
-
} catch (error) {
|
|
154
|
-
console.error("createSessionCookie:", error);
|
|
155
|
-
setResponseStatus(event, 401, "Unauthorized Request");
|
|
156
|
-
status = getResponseStatus(event);
|
|
157
|
-
text = getResponseStatusText(event);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return {
|
|
161
|
-
status,
|
|
162
|
-
text,
|
|
163
|
-
};
|
|
164
|
-
}),
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
router.post(
|
|
168
|
-
"/api/sessionLogout",
|
|
169
|
-
eventHandler((event) => {
|
|
170
|
-
deleteCookie(event, "__session");
|
|
171
|
-
setResponseStatus(event, 200, "Logged Out");
|
|
172
|
-
return "Logged Out";
|
|
173
|
-
}),
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (BATI.has("auth0")) {
|
|
178
|
-
const config: ConfigParams = {
|
|
179
|
-
authRequired: false, // Controls whether authentication is required for all routes
|
|
180
|
-
auth0Logout: true, // Uses Auth0 logout feature
|
|
181
|
-
baseURL: process.env.BASE_URL?.startsWith("http") ? process.env.BASE_URL : `http://localhost:${port}`, // The URL where the application is served
|
|
182
|
-
routes: {
|
|
183
|
-
login: "/api/auth/login", // Custom login route, default is "/login"
|
|
184
|
-
logout: "/api/auth/logout", // Custom logout route, default is "/logout"
|
|
185
|
-
callback: "/api/auth/callback", // Custom callback route, default is "/callback"
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
const expressApp = express();
|
|
190
|
-
|
|
191
|
-
app.use(fromNodeMiddleware(expressApp.use(auth(config))));
|
|
92
|
+
app.use(fromWebMiddleware(firebaseAuthMiddleware));
|
|
93
|
+
router.post("/api/sessionLogin", fromWebHandler(firebaseAuthLoginHandler));
|
|
94
|
+
router.post("/api/sessionLogout", fromWebHandler(firebaseAuthLogoutHandler));
|
|
192
95
|
}
|
|
193
96
|
|
|
194
97
|
if (BATI.has("trpc")) {
|
|
@@ -219,26 +122,7 @@ async function startServer() {
|
|
|
219
122
|
*
|
|
220
123
|
* @link {@see https://telefunc.com}
|
|
221
124
|
**/
|
|
222
|
-
router.post(
|
|
223
|
-
"/_telefunc",
|
|
224
|
-
eventHandler(async (event) => {
|
|
225
|
-
const request = toWebRequest(event);
|
|
226
|
-
const httpResponse = await telefunc({
|
|
227
|
-
url: request.url.toString(),
|
|
228
|
-
method: request.method,
|
|
229
|
-
body: await request.text(),
|
|
230
|
-
context: event,
|
|
231
|
-
});
|
|
232
|
-
const { body, statusCode, contentType } = httpResponse;
|
|
233
|
-
|
|
234
|
-
setResponseStatus(event, statusCode);
|
|
235
|
-
setResponseHeaders(event, {
|
|
236
|
-
"content-type": contentType,
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
return body;
|
|
240
|
-
}),
|
|
241
|
-
);
|
|
125
|
+
router.post("/_telefunc", fromWebHandler(telefuncHandler));
|
|
242
126
|
}
|
|
243
127
|
|
|
244
128
|
/**
|
|
@@ -246,30 +130,7 @@ async function startServer() {
|
|
|
246
130
|
*
|
|
247
131
|
* @link {@see https://vike.dev}
|
|
248
132
|
**/
|
|
249
|
-
router.use(
|
|
250
|
-
"/**",
|
|
251
|
-
eventHandler(async (event) => {
|
|
252
|
-
const pageContextInit = BATI.has("auth0")
|
|
253
|
-
? {
|
|
254
|
-
urlOriginal: event.node.req.originalUrl || event.node.req.url!,
|
|
255
|
-
user: event.node.req.oidc.user,
|
|
256
|
-
}
|
|
257
|
-
: BATI.has("firebase-auth")
|
|
258
|
-
? {
|
|
259
|
-
urlOriginal: event.node.req.originalUrl || event.node.req.url!,
|
|
260
|
-
user: event.context.user,
|
|
261
|
-
}
|
|
262
|
-
: { urlOriginal: event.node.req.originalUrl || event.node.req.url! };
|
|
263
|
-
|
|
264
|
-
const pageContext = await renderPage(pageContextInit);
|
|
265
|
-
const response = pageContext.httpResponse;
|
|
266
|
-
|
|
267
|
-
setResponseStatus(event, response?.statusCode);
|
|
268
|
-
setResponseHeaders(event, Object.fromEntries(response?.headers ?? []));
|
|
269
|
-
|
|
270
|
-
return response?.getBody();
|
|
271
|
-
}),
|
|
272
|
-
);
|
|
133
|
+
router.use("/**", fromWebHandler(vikeHandler));
|
|
273
134
|
|
|
274
135
|
app.use(router);
|
|
275
136
|
|
|
@@ -1 +1,6 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
|
+
interface Middleware<Context extends Record<string | number | symbol, unknown>> {
|
|
3
|
+
(request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
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>>;
|
|
6
|
+
export {};
|
|
@@ -42,7 +42,11 @@ var require_package = __commonJS({
|
|
|
42
42
|
license: "MIT",
|
|
43
43
|
devDependencies: {
|
|
44
44
|
"@auth/core": "^0.31.0",
|
|
45
|
+
"@batijs/authjs": "workspace:*",
|
|
45
46
|
"@batijs/compile": "workspace:*",
|
|
47
|
+
"@batijs/firebase-auth": "workspace:*",
|
|
48
|
+
"@batijs/shared-server": "workspace:^",
|
|
49
|
+
"@batijs/telefunc": "workspace:^",
|
|
46
50
|
"@batijs/trpc": "workspace:^",
|
|
47
51
|
"@hattip/adapter-node": "^0.0.45",
|
|
48
52
|
"@hattip/core": "^0.0.45",
|
|
@@ -50,10 +54,10 @@ var require_package = __commonJS({
|
|
|
50
54
|
"@hattip/vite": "^0.0.45",
|
|
51
55
|
"@trpc/server": "^10.45.2",
|
|
52
56
|
"@types/node": "^18.19.14",
|
|
57
|
+
dotenv: "^16.4.5",
|
|
53
58
|
hattip: "^0.0.33",
|
|
54
59
|
telefunc: "^0.1.72",
|
|
55
|
-
vike: "^0.4.
|
|
56
|
-
"vike-authjs": "^0.1.6",
|
|
60
|
+
vike: "^0.4.172",
|
|
57
61
|
vite: "^5.2.11"
|
|
58
62
|
},
|
|
59
63
|
dependencies: {
|
|
@@ -94,7 +98,7 @@ async function getPackageJson(props) {
|
|
|
94
98
|
warnIfReplaced: true
|
|
95
99
|
},
|
|
96
100
|
build: {
|
|
97
|
-
value: "NODE_ENV=production hattip build ./hattip-entry.ts --client",
|
|
101
|
+
value: "NODE_ENV=production hattip build ./hattip-entry.ts --target es2022 --client",
|
|
98
102
|
precedence: 20,
|
|
99
103
|
warnIfReplaced: true
|
|
100
104
|
}
|
|
@@ -110,7 +114,7 @@ async function getPackageJson(props) {
|
|
|
110
114
|
"hattip",
|
|
111
115
|
"vite",
|
|
112
116
|
"vike",
|
|
113
|
-
...props.meta.BATI.has("authjs") ? ["@auth/core", "
|
|
117
|
+
...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core", "dotenv"] : []
|
|
114
118
|
]
|
|
115
119
|
});
|
|
116
120
|
}
|
|
@@ -1,11 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
// BATI.has("auth0")
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import { authjsHandler, authjsSessionMiddleware } from "@batijs/authjs/server/authjs-handler";
|
|
4
|
+
import {
|
|
5
|
+
firebaseAuthLoginHandler,
|
|
6
|
+
firebaseAuthLogoutHandler,
|
|
7
|
+
firebaseAuthMiddleware,
|
|
8
|
+
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
9
|
+
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
10
|
+
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
2
11
|
import { appRouter } from "@batijs/trpc/trpc/server";
|
|
3
12
|
import type { HattipHandler } from "@hattip/core";
|
|
4
|
-
import { createRouter } from "@hattip/router";
|
|
13
|
+
import { createRouter, type RouteHandler } from "@hattip/router";
|
|
5
14
|
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
|
|
16
|
+
interface Middleware<Context extends Record<string | number | symbol, unknown>> {
|
|
17
|
+
(request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function handlerAdapter<Context extends Record<string | number | symbol, unknown>>(
|
|
21
|
+
handler: Middleware<Context>,
|
|
22
|
+
): RouteHandler<unknown, unknown> {
|
|
23
|
+
return (context) => {
|
|
24
|
+
const rawContext = context as unknown as Record<string, unknown>;
|
|
25
|
+
rawContext.context ??= {};
|
|
26
|
+
return handler(context.request, rawContext.context as Context);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
9
29
|
|
|
10
30
|
const router = createRouter();
|
|
11
31
|
|
|
@@ -15,21 +35,7 @@ if (BATI.has("telefunc")) {
|
|
|
15
35
|
*
|
|
16
36
|
* @link {@see https://telefunc.com}
|
|
17
37
|
**/
|
|
18
|
-
router.post("/_telefunc",
|
|
19
|
-
const httpResponse = await telefunc({
|
|
20
|
-
url: context.url.toString(),
|
|
21
|
-
method: context.method,
|
|
22
|
-
body: await context.request.text(),
|
|
23
|
-
context,
|
|
24
|
-
});
|
|
25
|
-
const { body, statusCode, contentType } = httpResponse;
|
|
26
|
-
return new Response(body, {
|
|
27
|
-
status: statusCode,
|
|
28
|
-
headers: {
|
|
29
|
-
"content-type": contentType,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
});
|
|
38
|
+
router.post("/_telefunc", handlerAdapter(telefuncHandler));
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
if (BATI.has("trpc")) {
|
|
@@ -50,40 +56,23 @@ if (BATI.has("trpc")) {
|
|
|
50
56
|
});
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
if (BATI.has("authjs")) {
|
|
59
|
+
if (BATI.has("authjs") || BATI.has("auth0")) {
|
|
54
60
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* TODO: Replace secret {@see https://authjs.dev/reference/core#secret}
|
|
58
|
-
* TODO: Choose and implement providers
|
|
59
|
-
*
|
|
60
|
-
* @link {@see https://authjs.dev/guides/providers/custom-provider}
|
|
61
|
+
* Append Auth.js session to context
|
|
61
62
|
**/
|
|
62
|
-
|
|
63
|
-
secret: "MY_SECRET", // See
|
|
64
|
-
|
|
65
|
-
providers: [
|
|
66
|
-
CredentialsProvider({
|
|
67
|
-
name: "Credentials",
|
|
68
|
-
credentials: {
|
|
69
|
-
username: { label: "Username", type: "text", placeholder: "username" },
|
|
70
|
-
password: { label: "Password", type: "password" },
|
|
71
|
-
},
|
|
72
|
-
async authorize() {
|
|
73
|
-
// Add logic here to look up the user from the credentials supplied
|
|
74
|
-
const user = { id: "1", name: "J Smith", email: "jsmith@example.com" };
|
|
63
|
+
router.use(handlerAdapter(authjsSessionMiddleware));
|
|
75
64
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
],
|
|
83
|
-
});
|
|
65
|
+
/**
|
|
66
|
+
* Auth.js route
|
|
67
|
+
* @link {@see https://authjs.dev/getting-started/installation}
|
|
68
|
+
**/
|
|
69
|
+
router.use("/api/auth/*", handlerAdapter(authjsHandler));
|
|
70
|
+
}
|
|
84
71
|
|
|
85
|
-
|
|
86
|
-
router.
|
|
72
|
+
if (BATI.has("firebase-auth")) {
|
|
73
|
+
router.use(handlerAdapter(firebaseAuthMiddleware));
|
|
74
|
+
router.post("/api/sessionLogin", handlerAdapter(firebaseAuthLoginHandler));
|
|
75
|
+
router.post("/api/sessionLogout", handlerAdapter(firebaseAuthLogoutHandler));
|
|
87
76
|
}
|
|
88
77
|
|
|
89
78
|
/**
|
|
@@ -91,15 +80,6 @@ if (BATI.has("authjs")) {
|
|
|
91
80
|
*
|
|
92
81
|
* @link {@see https://vike.dev}
|
|
93
82
|
**/
|
|
94
|
-
router.use(
|
|
95
|
-
const pageContextInit = { urlOriginal: context.request.url };
|
|
96
|
-
const pageContext = await renderPage(pageContextInit);
|
|
97
|
-
const response = pageContext.httpResponse;
|
|
98
|
-
|
|
99
|
-
return new Response(await response?.getBody(), {
|
|
100
|
-
status: response?.statusCode,
|
|
101
|
-
headers: response?.headers,
|
|
102
|
-
});
|
|
103
|
-
});
|
|
83
|
+
router.use(handlerAdapter(vikeHandler));
|
|
104
84
|
|
|
105
85
|
export default router.buildHandler() as HattipHandler;
|
|
@@ -42,19 +42,21 @@ var require_package = __commonJS({
|
|
|
42
42
|
license: "MIT",
|
|
43
43
|
devDependencies: {
|
|
44
44
|
"@auth/core": "^0.31.0",
|
|
45
|
+
"@batijs/authjs": "workspace:*",
|
|
45
46
|
"@batijs/compile": "workspace:*",
|
|
46
47
|
"@batijs/firebase-auth": "workspace:*",
|
|
48
|
+
"@batijs/shared-server": "workspace:^",
|
|
49
|
+
"@batijs/telefunc": "workspace:^",
|
|
47
50
|
"@batijs/trpc": "workspace:^",
|
|
48
51
|
"@hono/node-server": "^1.11.1",
|
|
49
52
|
"@hono/vite-dev-server": "^0.12.1",
|
|
50
53
|
"@trpc/server": "^10.45.2",
|
|
51
54
|
"@types/node": "^18.19.14",
|
|
52
|
-
|
|
53
|
-
hono: "^4.
|
|
55
|
+
dotenv: "^16.4.5",
|
|
56
|
+
hono: "^4.4.0",
|
|
54
57
|
telefunc: "^0.1.72",
|
|
55
|
-
tsx: "^4.
|
|
56
|
-
vike: "^0.4.
|
|
57
|
-
"vike-authjs": "^0.1.6",
|
|
58
|
+
tsx: "^4.11.0",
|
|
59
|
+
vike: "^0.4.172",
|
|
58
60
|
vite: "^5.2.11"
|
|
59
61
|
},
|
|
60
62
|
dependencies: {
|
|
@@ -112,7 +114,7 @@ async function getPackageJson(props) {
|
|
|
112
114
|
"tsx",
|
|
113
115
|
"vite",
|
|
114
116
|
"vike",
|
|
115
|
-
...props.meta.BATI.has("authjs") ? ["@auth/core", "
|
|
117
|
+
...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core", "dotenv"] : []
|
|
116
118
|
]
|
|
117
119
|
});
|
|
118
120
|
}
|