@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
|
@@ -0,0 +1,92 @@
|
|
|
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/authjs",
|
|
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
|
+
"@auth/core": "^0.34.2",
|
|
45
|
+
"@universal-middleware/core": "^0.2.3",
|
|
46
|
+
"@batijs/compile": "workspace:*",
|
|
47
|
+
"@types/node": "^18.19.14",
|
|
48
|
+
dotenv: "^16.4.5"
|
|
49
|
+
},
|
|
50
|
+
dependencies: {
|
|
51
|
+
"@batijs/core": "workspace:*"
|
|
52
|
+
},
|
|
53
|
+
files: [
|
|
54
|
+
"dist/"
|
|
55
|
+
],
|
|
56
|
+
bati: {
|
|
57
|
+
if: {
|
|
58
|
+
flag: {
|
|
59
|
+
$in: [
|
|
60
|
+
"authjs",
|
|
61
|
+
"auth0"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
exports: {
|
|
67
|
+
"./server/authjs-handler": {
|
|
68
|
+
types: "./dist/types/server/authjs-handler.d.ts"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
typesVersions: {
|
|
72
|
+
"*": {
|
|
73
|
+
"server/authjs-handler": [
|
|
74
|
+
"./dist/types/server/authjs-handler.d.ts"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// files/$package.json.ts
|
|
83
|
+
import { addDependency, loadAsJson } from "@batijs/core";
|
|
84
|
+
async function getPackageJson(props) {
|
|
85
|
+
const packageJson = await loadAsJson(props);
|
|
86
|
+
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
|
|
87
|
+
dependencies: ["@auth/core", "@universal-middleware/core", "dotenv"]
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
getPackageJson as default
|
|
92
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Auth, createActionURL, setEnvDefaults
|
|
1
|
+
import { Auth, type AuthConfig, createActionURL, setEnvDefaults } from "@auth/core";
|
|
2
2
|
import Auth0 from "@auth/core/providers/auth0";
|
|
3
3
|
import CredentialsProvider from "@auth/core/providers/credentials";
|
|
4
4
|
import type { Session } from "@auth/core/types";
|
|
5
|
+
import type { Get, UniversalHandler, UniversalMiddleware } from "@universal-middleware/core";
|
|
5
6
|
|
|
6
7
|
const env: Record<string, string | undefined> =
|
|
7
8
|
typeof process?.env !== "undefined"
|
|
@@ -76,25 +77,25 @@ export async function getSession(req: Request, config: Omit<AuthConfig, "raw">):
|
|
|
76
77
|
* Add Auth.js session to context
|
|
77
78
|
* @link {@see https://authjs.dev/getting-started/session-management/get-session}
|
|
78
79
|
**/
|
|
79
|
-
export async
|
|
80
|
-
request: Request,
|
|
81
|
-
context: Record<string | number | symbol, unknown>,
|
|
82
|
-
): Promise<void> {
|
|
80
|
+
export const authjsSessionMiddleware = (() => async (request, context) => {
|
|
83
81
|
try {
|
|
84
|
-
|
|
82
|
+
return {
|
|
83
|
+
...context,
|
|
84
|
+
session: await getSession(request, authjsConfig),
|
|
85
|
+
};
|
|
85
86
|
} catch (error) {
|
|
86
87
|
console.debug("authjsSessionMiddleware:", error);
|
|
87
|
-
|
|
88
|
+
return {
|
|
89
|
+
...context,
|
|
90
|
+
session: null,
|
|
91
|
+
};
|
|
88
92
|
}
|
|
89
|
-
}
|
|
93
|
+
}) satisfies Get<[], UniversalMiddleware>;
|
|
90
94
|
|
|
91
95
|
/**
|
|
92
96
|
* Auth.js route
|
|
93
97
|
* @link {@see https://authjs.dev/getting-started/installation}
|
|
94
98
|
**/
|
|
95
|
-
export
|
|
96
|
-
request: Request,
|
|
97
|
-
_context?: Context,
|
|
98
|
-
): Promise<Response> {
|
|
99
|
+
export const authjsHandler = (() => async (request) => {
|
|
99
100
|
return Auth(request, authjsConfig);
|
|
100
|
-
}
|
|
101
|
+
}) satisfies Get<[], UniversalHandler>;
|
|
@@ -8,9 +8,11 @@ export declare function getSession(req: Request, config: Omit<AuthConfig, "raw">
|
|
|
8
8
|
* Add Auth.js session to context
|
|
9
9
|
* @link {@see https://authjs.dev/getting-started/session-management/get-session}
|
|
10
10
|
**/
|
|
11
|
-
export declare
|
|
11
|
+
export declare const authjsSessionMiddleware: () => (request: Request, context: Universal.Context) => Promise<{
|
|
12
|
+
session: Session | null;
|
|
13
|
+
}>;
|
|
12
14
|
/**
|
|
13
15
|
* Auth.js route
|
|
14
16
|
* @link {@see https://authjs.dev/getting-started/installation}
|
|
15
17
|
**/
|
|
16
|
-
export declare
|
|
18
|
+
export declare const authjsHandler: () => (request: Request) => Promise<Response>;
|
|
@@ -45,8 +45,8 @@ var require_package = __commonJS({
|
|
|
45
45
|
"@hattip/adapter-cloudflare-workers": "^0.0.47",
|
|
46
46
|
"@types/node": "^18.19.14",
|
|
47
47
|
"npm-run-all2": "^6.2.2",
|
|
48
|
-
"vike-cloudflare": "^0.0.
|
|
49
|
-
wrangler: "^3.
|
|
48
|
+
"vike-cloudflare": "^0.0.6",
|
|
49
|
+
wrangler: "^3.72.0"
|
|
50
50
|
},
|
|
51
51
|
dependencies: {
|
|
52
52
|
"@batijs/core": "workspace:*"
|
|
@@ -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>>;
|
|
@@ -47,10 +47,10 @@ var require_package = __commonJS({
|
|
|
47
47
|
"eslint-config-prettier": "^9.1.0",
|
|
48
48
|
"eslint-plugin-prettier": "^5.2.1",
|
|
49
49
|
"eslint-plugin-react": "^7.35.0",
|
|
50
|
-
"eslint-plugin-solid": "^0.14.
|
|
50
|
+
"eslint-plugin-solid": "^0.14.2",
|
|
51
51
|
"eslint-plugin-vue": "^9.27.0",
|
|
52
52
|
globals: "^15.9.0",
|
|
53
|
-
"typescript-eslint": "^8.0
|
|
53
|
+
"typescript-eslint": "^8.1.0",
|
|
54
54
|
"vue-eslint-parser": "^9.4.3"
|
|
55
55
|
},
|
|
56
56
|
dependencies: {
|
|
@@ -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:*",
|
|
@@ -54,7 +55,7 @@ var require_package = __commonJS({
|
|
|
54
55
|
"@types/cookie-parser": "^1.4.7",
|
|
55
56
|
"@types/express": "^4.17.21",
|
|
56
57
|
"@types/node": "^18.19.14",
|
|
57
|
-
"@universal-middleware/express": "^0.
|
|
58
|
+
"@universal-middleware/express": "^0.2.1",
|
|
58
59
|
"cookie-parser": "^1.4.6",
|
|
59
60
|
"cross-env": "^7.0.3",
|
|
60
61
|
dotenv: "^16.4.5",
|
|
@@ -62,8 +63,8 @@ var require_package = __commonJS({
|
|
|
62
63
|
"express-openid-connect": "^2.17.1",
|
|
63
64
|
telefunc: "^0.1.76",
|
|
64
65
|
tsx: "^4.17.0",
|
|
65
|
-
vike: "^0.4.
|
|
66
|
-
vite: "^5.4.
|
|
66
|
+
vike: "^0.4.187",
|
|
67
|
+
vite: "^5.4.1"
|
|
67
68
|
},
|
|
68
69
|
dependencies: {
|
|
69
70
|
"@batijs/core": "workspace:*"
|
|
@@ -124,7 +125,6 @@ async function getPackageJson(props) {
|
|
|
124
125
|
"tsx",
|
|
125
126
|
"vite",
|
|
126
127
|
"vike",
|
|
127
|
-
...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core", "dotenv"] : [],
|
|
128
128
|
...props.meta.BATI.has("firebase-auth") ? ["cookie-parser"] : []
|
|
129
129
|
]
|
|
130
130
|
});
|
|
@@ -8,6 +8,16 @@ import {
|
|
|
8
8
|
firebaseAuthLogoutHandler,
|
|
9
9
|
firebaseAuthMiddleware,
|
|
10
10
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
11
|
+
import {
|
|
12
|
+
luciaAuthContextMiddleware,
|
|
13
|
+
luciaAuthCookieMiddleware,
|
|
14
|
+
luciaAuthLoginHandler,
|
|
15
|
+
luciaAuthLogoutHandler,
|
|
16
|
+
luciaAuthSignupHandler,
|
|
17
|
+
luciaCsrfMiddleware,
|
|
18
|
+
luciaGithubCallbackHandler,
|
|
19
|
+
luciaGithubLoginHandler,
|
|
20
|
+
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
11
21
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
12
22
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
13
23
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
@@ -48,19 +58,31 @@ async function startServer() {
|
|
|
48
58
|
/**
|
|
49
59
|
* Append Auth.js session to context
|
|
50
60
|
**/
|
|
51
|
-
app.use(createMiddleware(authjsSessionMiddleware));
|
|
61
|
+
app.use(createMiddleware(authjsSessionMiddleware)());
|
|
52
62
|
|
|
53
63
|
/**
|
|
54
64
|
* Auth.js route
|
|
55
65
|
* @link {@see https://authjs.dev/getting-started/installation}
|
|
56
66
|
**/
|
|
57
|
-
app.all("/api/auth/*", createHandler(authjsHandler));
|
|
67
|
+
app.all("/api/auth/*", createHandler(authjsHandler)());
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
if (BATI.has("firebase-auth")) {
|
|
61
|
-
app.use(createMiddleware(firebaseAuthMiddleware));
|
|
62
|
-
app.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler));
|
|
63
|
-
app.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler));
|
|
71
|
+
app.use(createMiddleware(firebaseAuthMiddleware)());
|
|
72
|
+
app.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler)());
|
|
73
|
+
app.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler)());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (BATI.has("lucia-auth")) {
|
|
77
|
+
app.use(createMiddleware(luciaCsrfMiddleware)());
|
|
78
|
+
app.use(createMiddleware(luciaAuthContextMiddleware)());
|
|
79
|
+
app.use(createMiddleware(luciaAuthCookieMiddleware)());
|
|
80
|
+
|
|
81
|
+
app.post("/api/signup", createHandler(luciaAuthSignupHandler)());
|
|
82
|
+
app.post("/api/login", createHandler(luciaAuthLoginHandler)());
|
|
83
|
+
app.post("/api/logout", createHandler(luciaAuthLogoutHandler)());
|
|
84
|
+
app.get("/api/login/github", createHandler(luciaGithubLoginHandler)());
|
|
85
|
+
app.get("/api/login/github/callback", createHandler(luciaGithubCallbackHandler)());
|
|
64
86
|
}
|
|
65
87
|
|
|
66
88
|
if (BATI.has("trpc")) {
|
|
@@ -86,15 +108,15 @@ async function startServer() {
|
|
|
86
108
|
*
|
|
87
109
|
* @link {@see https://telefunc.com}
|
|
88
110
|
**/
|
|
89
|
-
app.post("/_telefunc", createHandler(telefuncHandler));
|
|
111
|
+
app.post("/_telefunc", createHandler(telefuncHandler)());
|
|
90
112
|
}
|
|
91
113
|
|
|
92
114
|
if (BATI.has("ts-rest")) {
|
|
93
|
-
app.all("/api/*", createHandler(tsRestHandler));
|
|
115
|
+
app.all("/api/*", createHandler(tsRestHandler)());
|
|
94
116
|
}
|
|
95
117
|
|
|
96
118
|
if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
97
|
-
app.post("/api/todo/create", createHandler(createTodoHandler));
|
|
119
|
+
app.post("/api/todo/create", createHandler(createTodoHandler)());
|
|
98
120
|
}
|
|
99
121
|
|
|
100
122
|
/**
|
|
@@ -102,7 +124,7 @@ async function startServer() {
|
|
|
102
124
|
*
|
|
103
125
|
* @link {@see https://vike.dev}
|
|
104
126
|
**/
|
|
105
|
-
app.all("*", createHandler(vikeHandler));
|
|
127
|
+
app.all("*", createHandler(vikeHandler)());
|
|
106
128
|
|
|
107
129
|
app.listen(port, () => {
|
|
108
130
|
console.log(`Server listening on http://localhost:${port}`);
|
|
@@ -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,14 @@ var require_package = __commonJS({
|
|
|
55
56
|
"@trpc/server": "^10.45.2",
|
|
56
57
|
"@types/express": "^4.17.21",
|
|
57
58
|
"@types/node": "^18.19.14",
|
|
58
|
-
"@universal-middleware/
|
|
59
|
+
"@universal-middleware/fastify": "^0.2.1",
|
|
59
60
|
"cross-env": "^7.0.3",
|
|
60
61
|
dotenv: "^16.4.5",
|
|
61
62
|
fastify: "^4.28.1",
|
|
62
63
|
telefunc: "^0.1.76",
|
|
63
64
|
tsx: "^4.17.0",
|
|
64
|
-
vike: "^0.4.
|
|
65
|
-
vite: "^5.4.
|
|
65
|
+
vike: "^0.4.187",
|
|
66
|
+
vite: "^5.4.1"
|
|
66
67
|
},
|
|
67
68
|
dependencies: {
|
|
68
69
|
"@batijs/core": "workspace:*"
|
|
@@ -116,13 +117,12 @@ async function getPackageJson(props) {
|
|
|
116
117
|
dependencies: [
|
|
117
118
|
"@fastify/middie",
|
|
118
119
|
"@fastify/static",
|
|
119
|
-
"@universal-middleware/
|
|
120
|
+
"@universal-middleware/fastify",
|
|
120
121
|
"cross-env",
|
|
121
122
|
"fastify",
|
|
122
123
|
"tsx",
|
|
123
124
|
"vike",
|
|
124
|
-
"vite"
|
|
125
|
-
...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core", "dotenv"] : []
|
|
125
|
+
"vite"
|
|
126
126
|
]
|
|
127
127
|
});
|
|
128
128
|
}
|
|
@@ -8,6 +8,16 @@ import {
|
|
|
8
8
|
firebaseAuthLogoutHandler,
|
|
9
9
|
firebaseAuthMiddleware,
|
|
10
10
|
} from "@batijs/firebase-auth/server/firebase-auth-middleware";
|
|
11
|
+
import {
|
|
12
|
+
luciaAuthContextMiddleware,
|
|
13
|
+
luciaAuthCookieMiddleware,
|
|
14
|
+
luciaAuthLoginHandler,
|
|
15
|
+
luciaAuthLogoutHandler,
|
|
16
|
+
luciaAuthSignupHandler,
|
|
17
|
+
luciaCsrfMiddleware,
|
|
18
|
+
luciaGithubCallbackHandler,
|
|
19
|
+
luciaGithubLoginHandler,
|
|
20
|
+
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
11
21
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
12
22
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
13
23
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
@@ -18,9 +28,8 @@ import {
|
|
|
18
28
|
fastifyTRPCPlugin,
|
|
19
29
|
type FastifyTRPCPluginOptions,
|
|
20
30
|
} from "@trpc/server/adapters/fastify";
|
|
21
|
-
import { createRequestAdapter } from "@universal-middleware/express";
|
|
22
31
|
import Fastify from "fastify";
|
|
23
|
-
import
|
|
32
|
+
import { createHandler, createMiddleware } from "@universal-middleware/fastify";
|
|
24
33
|
|
|
25
34
|
const __filename = fileURLToPath(import.meta.url);
|
|
26
35
|
const __dirname = dirname(__filename);
|
|
@@ -28,44 +37,11 @@ const root = __dirname;
|
|
|
28
37
|
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
29
38
|
const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678;
|
|
30
39
|
|
|
31
|
-
interface Middleware<Context extends Record<string | number | symbol, unknown>> {
|
|
32
|
-
(request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function handlerAdapter<Context extends Record<string | number | symbol, unknown>>(
|
|
36
|
-
handler: Middleware<Context>,
|
|
37
|
-
) {
|
|
38
|
-
const requestAdapter = createRequestAdapter();
|
|
39
|
-
return (async (request, reply) => {
|
|
40
|
-
const config = request.routeOptions.config as unknown as Record<string, unknown>;
|
|
41
|
-
config.context ??= {};
|
|
42
|
-
const response = await handler(requestAdapter(request.raw), config.context as Context);
|
|
43
|
-
|
|
44
|
-
if (response) {
|
|
45
|
-
if (!response.body) {
|
|
46
|
-
// Fastify currently doesn't send a response for body is null.
|
|
47
|
-
// To mimic express behavior, we convert the body to an empty ReadableStream.
|
|
48
|
-
Object.defineProperty(response, "body", {
|
|
49
|
-
value: new ReadableStream({
|
|
50
|
-
start(controller) {
|
|
51
|
-
controller.close();
|
|
52
|
-
},
|
|
53
|
-
}),
|
|
54
|
-
writable: false,
|
|
55
|
-
configurable: true,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return reply.send(response);
|
|
60
|
-
}
|
|
61
|
-
}) satisfies RouteHandlerMethod;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
40
|
async function startServer() {
|
|
65
41
|
const app = Fastify();
|
|
66
42
|
|
|
67
43
|
// Avoid pre-parsing body, otherwise it will cause issue with universal handlers
|
|
68
|
-
// This will probably change in the future though, you can follow https://github.com/magne4000/universal-
|
|
44
|
+
// This will probably change in the future though, you can follow https://github.com/magne4000/universal-middleware for updates
|
|
69
45
|
app.removeAllContentTypeParsers();
|
|
70
46
|
app.addContentTypeParser("*", function (_request, _payload, done) {
|
|
71
47
|
done(null, "");
|
|
@@ -96,19 +72,31 @@ async function startServer() {
|
|
|
96
72
|
/**
|
|
97
73
|
* Append Auth.js session to context
|
|
98
74
|
**/
|
|
99
|
-
app.
|
|
75
|
+
app.register(createMiddleware(authjsSessionMiddleware)());
|
|
100
76
|
|
|
101
77
|
/**
|
|
102
78
|
* Auth.js route
|
|
103
79
|
* @link {@see https://authjs.dev/getting-started/installation}
|
|
104
80
|
**/
|
|
105
|
-
app.all("/api/auth/*",
|
|
81
|
+
app.all("/api/auth/*", createHandler(authjsHandler)());
|
|
106
82
|
}
|
|
107
83
|
|
|
108
84
|
if (BATI.has("firebase-auth")) {
|
|
109
|
-
app.
|
|
110
|
-
app.post("/api/sessionLogin",
|
|
111
|
-
app.post("/api/sessionLogout",
|
|
85
|
+
app.register(createMiddleware(firebaseAuthMiddleware)());
|
|
86
|
+
app.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler)());
|
|
87
|
+
app.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler)());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (BATI.has("lucia-auth")) {
|
|
91
|
+
app.register(createMiddleware(luciaCsrfMiddleware)());
|
|
92
|
+
app.register(createMiddleware(luciaAuthContextMiddleware)());
|
|
93
|
+
app.register(createMiddleware(luciaAuthCookieMiddleware)());
|
|
94
|
+
|
|
95
|
+
app.post("/api/signup", createHandler(luciaAuthSignupHandler)());
|
|
96
|
+
app.post("/api/login", createHandler(luciaAuthLoginHandler)());
|
|
97
|
+
app.post("/api/logout", createHandler(luciaAuthLogoutHandler)());
|
|
98
|
+
app.get("/api/login/github", createHandler(luciaGithubLoginHandler)());
|
|
99
|
+
app.get("/api/login/github/callback", createHandler(luciaGithubCallbackHandler)());
|
|
112
100
|
}
|
|
113
101
|
|
|
114
102
|
if (BATI.has("trpc")) {
|
|
@@ -138,15 +126,15 @@ async function startServer() {
|
|
|
138
126
|
*
|
|
139
127
|
* @link {@see https://telefunc.com}
|
|
140
128
|
**/
|
|
141
|
-
app.post<{ Body: string }>("/_telefunc",
|
|
129
|
+
app.post<{ Body: string }>("/_telefunc", createHandler(telefuncHandler)());
|
|
142
130
|
}
|
|
143
131
|
|
|
144
132
|
if (BATI.has("ts-rest")) {
|
|
145
|
-
app.all("/api/*",
|
|
133
|
+
app.all("/api/*", createHandler(tsRestHandler));
|
|
146
134
|
}
|
|
147
135
|
|
|
148
136
|
if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
|
|
149
|
-
app.post("/api/todo/create",
|
|
137
|
+
app.post("/api/todo/create", createHandler(createTodoHandler)());
|
|
150
138
|
}
|
|
151
139
|
|
|
152
140
|
/**
|
|
@@ -154,7 +142,7 @@ async function startServer() {
|
|
|
154
142
|
*
|
|
155
143
|
* @link {@see https://vike.dev}
|
|
156
144
|
**/
|
|
157
|
-
app.all("/*",
|
|
145
|
+
app.all("/*", createHandler(vikeHandler)());
|
|
158
146
|
|
|
159
147
|
return app;
|
|
160
148
|
}
|
|
@@ -1,7 +1,3 @@
|
|
|
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 handlerAdapter<Context extends Record<string | number | symbol, unknown>>(handler: Middleware<Context>): (this: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>, reply: import("fastify").FastifyReply<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>) => Promise<undefined>;
|
|
6
2
|
declare const _default: (req: Request, res: Response) => Promise<void>;
|
|
7
3
|
export default _default;
|
|
@@ -44,13 +44,14 @@ var require_package = __commonJS({
|
|
|
44
44
|
"@batijs/compile": "workspace:*",
|
|
45
45
|
"@types/cookie": "^0.6.0",
|
|
46
46
|
"@types/node": "^18.19.14",
|
|
47
|
+
"@universal-middleware/core": "^0.2.3",
|
|
47
48
|
cookie: "^0.6.0",
|
|
48
49
|
dotenv: "^16.4.5",
|
|
49
|
-
firebase: "^10.
|
|
50
|
+
firebase: "^10.13.0",
|
|
50
51
|
"firebase-admin": "^12.3.1",
|
|
51
52
|
firebaseui: "^6.1.0",
|
|
52
|
-
vike: "^0.4.
|
|
53
|
-
vite: "^5.4.
|
|
53
|
+
vike: "^0.4.187",
|
|
54
|
+
vite: "^5.4.1"
|
|
54
55
|
},
|
|
55
56
|
dependencies: {
|
|
56
57
|
"@batijs/core": "workspace:*"
|
|
@@ -115,7 +116,7 @@ async function getPackageJson(props) {
|
|
|
115
116
|
const packageJson = await loadAsJson(props);
|
|
116
117
|
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
|
|
117
118
|
devDependencies: ["dotenv", "@types/cookie"],
|
|
118
|
-
dependencies: ["firebase", "firebase-admin", "firebaseui", "cookie"]
|
|
119
|
+
dependencies: ["firebase", "firebase-admin", "firebaseui", "cookie", "@universal-middleware/core"]
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
122
|
export {
|