@batijs/cli 0.0.176 → 0.0.178

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.
Files changed (92) hide show
  1. package/dist/boilerplates/@batijs/auth0/files/$.env.js +19 -0
  2. package/dist/boilerplates/@batijs/auth0/files/$README.md.js +43 -0
  3. package/dist/boilerplates/@batijs/auth0/files/vike.d.ts +11 -0
  4. package/dist/boilerplates/@batijs/compiled/files/$package.json.js +1 -1
  5. package/dist/boilerplates/@batijs/edgedb/files/$package.json.js +1 -1
  6. package/dist/boilerplates/@batijs/eslint/files/$package.json.js +1 -1
  7. package/dist/boilerplates/@batijs/express/files/$package.json.js +7 -3
  8. package/dist/boilerplates/@batijs/express/files/express-entry.ts +33 -11
  9. package/dist/boilerplates/@batijs/express/files/vike.d.ts +10 -0
  10. package/dist/boilerplates/@batijs/express/types/express-entry.d.ts +1 -1
  11. package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +1 -7
  12. package/dist/boilerplates/@batijs/firebase-auth/files/firebase/$service-account.json.js +20 -0
  13. package/dist/boilerplates/@batijs/firebase-auth/files/libs/firebaseAdmin.ts +6 -6
  14. package/dist/boilerplates/@batijs/firebase-auth/files/libs/firebaseUI.ts +26 -26
  15. package/dist/boilerplates/@batijs/firebase-auth/files/pages/+firebaseApp.ts +2 -1
  16. package/dist/boilerplates/@batijs/firebase-auth/files/pages/login/+guard.ts +5 -5
  17. package/dist/boilerplates/@batijs/firebase-auth/files/{types.ts → vike.d.ts} +0 -9
  18. package/dist/boilerplates/@batijs/firebase-auth/types/pages/login/+guard.d.ts +1 -1
  19. package/dist/boilerplates/@batijs/h3/files/$package.json.js +11 -3
  20. package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +37 -16
  21. package/dist/boilerplates/@batijs/h3/files/vike.d.ts +22 -0
  22. package/dist/boilerplates/@batijs/h3/types/h3-entry.d.ts +1 -6
  23. package/dist/boilerplates/@batijs/hattip/files/$package.json.js +1 -1
  24. package/dist/boilerplates/@batijs/prettier/files/$package.json.js +1 -1
  25. package/dist/boilerplates/@batijs/prisma/files/$package.json.js +1 -1
  26. package/dist/boilerplates/@batijs/react/files/$package.json.js +2 -2
  27. package/dist/boilerplates/@batijs/react/files/layouts/LayoutDefault.tsx +1 -1
  28. package/dist/boilerplates/@batijs/react/files/pages/+config.ts +3 -3
  29. package/dist/boilerplates/@batijs/react/files/pages/_error/+Page.tsx +1 -1
  30. package/dist/boilerplates/@batijs/react/files/pages/index/+Page.tsx +1 -1
  31. package/dist/boilerplates/@batijs/react/files/pages/star-wars/@id/+Page.tsx +1 -1
  32. package/dist/boilerplates/@batijs/react/files/pages/star-wars/@id/+data.ts +1 -1
  33. package/dist/boilerplates/@batijs/react/files/pages/star-wars/@id/+title.ts +1 -1
  34. package/dist/boilerplates/@batijs/react/files/pages/star-wars/index/+Page.tsx +1 -1
  35. package/dist/boilerplates/@batijs/react/files/pages/star-wars/index/+data.ts +1 -1
  36. package/dist/boilerplates/@batijs/react/files/pages/star-wars/index/+title.ts +1 -1
  37. package/dist/boilerplates/@batijs/react/types/pages/+config.d.ts +3 -3
  38. package/dist/boilerplates/@batijs/react/types/pages/star-wars/@id/+data.d.ts +1 -1
  39. package/dist/boilerplates/@batijs/react/types/pages/star-wars/@id/+title.d.ts +1 -1
  40. package/dist/boilerplates/@batijs/react/types/pages/star-wars/index/+data.d.ts +1 -1
  41. package/dist/boilerplates/@batijs/react/types/pages/star-wars/index/+title.d.ts +1 -1
  42. package/dist/boilerplates/@batijs/react-firebase-auth/files/pages/login/+Page.tsx +44 -44
  43. package/dist/boilerplates/@batijs/react-telefunc/files/pages/todo/+Page.tsx +2 -2
  44. package/dist/boilerplates/@batijs/react-telefunc/types/pages/todo/TodoList.d.ts +1 -1
  45. package/dist/boilerplates/@batijs/react-trpc/files/pages/todo-trpc/+Page.tsx +2 -2
  46. package/dist/boilerplates/@batijs/shared/files/tsconfig.json +2 -2
  47. package/dist/boilerplates/@batijs/solid/files/$package.json.js +3 -3
  48. package/dist/boilerplates/@batijs/solid/files/components/Link.tsx +1 -1
  49. package/dist/boilerplates/@batijs/solid/files/layouts/LayoutDefault.tsx +1 -1
  50. package/dist/boilerplates/@batijs/solid/files/pages/+config.ts +3 -3
  51. package/dist/boilerplates/@batijs/solid/files/pages/index/+Page.tsx +1 -1
  52. package/dist/boilerplates/@batijs/solid/files/pages/star-wars/@id/+Page.tsx +1 -1
  53. package/dist/boilerplates/@batijs/solid/files/pages/star-wars/@id/+data.ts +1 -1
  54. package/dist/boilerplates/@batijs/solid/files/pages/star-wars/@id/+title.ts +1 -1
  55. package/dist/boilerplates/@batijs/solid/files/pages/star-wars/index/+Page.tsx +1 -1
  56. package/dist/boilerplates/@batijs/solid/files/pages/star-wars/index/+data.ts +1 -1
  57. package/dist/boilerplates/@batijs/solid/files/pages/star-wars/index/+title.ts +1 -1
  58. package/dist/boilerplates/@batijs/solid/types/pages/+config.d.ts +2 -2
  59. package/dist/boilerplates/@batijs/solid/types/pages/star-wars/@id/+data.d.ts +1 -1
  60. package/dist/boilerplates/@batijs/solid/types/pages/star-wars/@id/+title.d.ts +1 -1
  61. package/dist/boilerplates/@batijs/solid/types/pages/star-wars/index/+data.d.ts +1 -1
  62. package/dist/boilerplates/@batijs/solid/types/pages/star-wars/index/+title.d.ts +1 -1
  63. package/dist/boilerplates/@batijs/solid-firebase-auth/files/pages/login/+Page.tsx +43 -43
  64. package/dist/boilerplates/@batijs/solid-telefunc/files/pages/todo/+Page.tsx +1 -1
  65. package/dist/boilerplates/@batijs/solid-trpc/files/pages/todo-trpc/+Page.tsx +1 -1
  66. package/dist/boilerplates/@batijs/tailwindcss/files/$package.json.js +7 -2
  67. package/dist/boilerplates/@batijs/tailwindcss/files/postcss.config.js +1 -1
  68. package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +1 -1
  69. package/dist/boilerplates/@batijs/trpc/files/$package.json.js +1 -1
  70. package/dist/boilerplates/@batijs/trpc/files/trpc/client.ts +1 -1
  71. package/dist/boilerplates/@batijs/trpc/files/trpc/vite-plugin.ts +1 -1
  72. package/dist/boilerplates/@batijs/vercel/files/$package.json.js +1 -1
  73. package/dist/boilerplates/@batijs/vue/files/$package.json.js +4 -4
  74. package/dist/boilerplates/@batijs/vue/files/pages/+config.ts +1 -1
  75. package/dist/boilerplates/@batijs/vue/files/pages/index/+Page.vue +5 -11
  76. package/dist/boilerplates/@batijs/vue/files/pages/star-wars/@id/+Page.vue +1 -1
  77. package/dist/boilerplates/@batijs/vue/files/pages/star-wars/@id/+data.ts +1 -1
  78. package/dist/boilerplates/@batijs/vue/files/pages/star-wars/@id/+title.ts +1 -1
  79. package/dist/boilerplates/@batijs/vue/files/pages/star-wars/index/+Page.vue +1 -1
  80. package/dist/boilerplates/@batijs/vue/files/pages/star-wars/index/+data.ts +1 -1
  81. package/dist/boilerplates/@batijs/vue/files/pages/star-wars/index/+title.ts +1 -1
  82. package/dist/boilerplates/@batijs/vue/types/pages/star-wars/@id/+data.d.ts +1 -1
  83. package/dist/boilerplates/@batijs/vue/types/pages/star-wars/@id/+title.d.ts +1 -1
  84. package/dist/boilerplates/@batijs/vue/types/pages/star-wars/index/+data.d.ts +1 -1
  85. package/dist/boilerplates/@batijs/vue/types/pages/star-wars/index/+title.d.ts +1 -1
  86. package/dist/boilerplates/@batijs/vue-telefunc/files/pages/todo/+Page.vue +1 -1
  87. package/dist/boilerplates/@batijs/vue-trpc/files/pages/todo-trpc/+Page.vue +1 -1
  88. package/dist/boilerplates/boilerplates.json +11 -0
  89. package/dist/index.js +257 -217
  90. package/package.json +5 -5
  91. package/dist/boilerplates/@batijs/firebase-auth/files/firebase/service-account-example.json +0 -13
  92. package/dist/boilerplates/@batijs/firebase-auth/types/types.d.ts +0 -18
@@ -0,0 +1,19 @@
1
+ // files/$.env.ts
2
+ import { appendToEnv, randomBytes } from "@batijs/core";
3
+ async function getEnv(props) {
4
+ const auth0ClientId = process.env.TEST_AUTH0_CLIENT_ID;
5
+ const auth0BaseUrl = process.env.TEST_AUTH0_ISSUER_BASE_URL;
6
+ let envContent = await props.readfile?.();
7
+ envContent = appendToEnv(
8
+ envContent,
9
+ "SECRET",
10
+ randomBytes(32).toString("hex"),
11
+ "Randomly generated by Bati CLI, used by Auth0"
12
+ );
13
+ envContent = appendToEnv(envContent, "CLIENT_ID", auth0ClientId ?? "", "Auth0 Client ID");
14
+ envContent = appendToEnv(envContent, "ISSUER_BASE_URL", auth0BaseUrl ?? "", "Auth0 base URL");
15
+ return envContent;
16
+ }
17
+ export {
18
+ getEnv as default
19
+ };
@@ -0,0 +1,43 @@
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
+ ## *Auth0*
7
+ - Sign up or login to an Auth0 account, then go to [your Dashboard](https://manage.auth0.com/dashboard/)
8
+ - Create Application -> Regular Web Application
9
+ - What technology are you using for your project? -> Node.js (Express) -> Integrate Now
10
+ - Configure Auth0:
11
+ - Allowed Callback URL: http://localhost:3000/api/auth/callback
12
+ - Allowed Logout URLs: http://localhost:3000
13
+ - Save Changes
14
+ - Copy your \`clientID\` and \`issuerBaseURL\` and paste it in \`.env\` file like this:
15
+
16
+ \`\`\`env
17
+ // .env
18
+ SECRET=<random string>
19
+ CLIENT_ID=<Client ID>
20
+ ISSUER_BASE_URL=https://<your-auth0-domain>.<eu>.auth0.com
21
+ \`\`\`
22
+
23
+ > [!NOTE]
24
+ > Environment variables that are automatically made available to Auth0 :
25
+ > - \`SECRET\`
26
+ > - \`ISSUER_BASE_URL\`
27
+ > - \`BASE_URL\`
28
+ > - \`CLIENT_ID\`
29
+ > - \`CLIENT_SECRET\`
30
+
31
+ > [!NOTE]
32
+ > Login route is \`http://localhost:3000/api/auth/login\`.
33
+ > Logout route is \`http://localhost:3000/api/auth/logout\`.
34
+
35
+ - Read more [Auth0 Express SDK Quickstarts: Login](https://auth0.com/docs/quickstart/webapp/express)
36
+ - Read more [Auth0 Express SDK Quickstarts: Add Login to your Express App](https://auth0.com/docs/quickstart/webapp/express/interactive)
37
+ `;
38
+ content.addTodo(todo);
39
+ return content.finalize();
40
+ }
41
+ export {
42
+ getReadme as default
43
+ };
@@ -0,0 +1,11 @@
1
+ import type { RequestContext } from "express-openid-connect";
2
+
3
+ declare global {
4
+ namespace Vike {
5
+ interface PageContext {
6
+ user?: RequestContext["user"] | null;
7
+ }
8
+ }
9
+ }
10
+
11
+ export {};
@@ -66,7 +66,7 @@ var require_package = __commonJS({
66
66
  import { addDependency, loadAsJson } from "@batijs/core";
67
67
  async function getPackageJson(props) {
68
68
  const packageJson = await loadAsJson(props);
69
- return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
69
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
70
70
  devDependencies: ["vite-plugin-compiled-react"],
71
71
  dependencies: ["@compiled/react"]
72
72
  });
@@ -73,7 +73,7 @@ async function getPackageJson(props) {
73
73
  const packageJson = await loadAsJson(props);
74
74
  packageJson.scripts["edgedb:generate-queries"] = "@edgedb/generate queries";
75
75
  packageJson.scripts["edgedb:generate-edgeql-js"] = "@edgedb/generate edgeql-js";
76
- return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
76
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
77
77
  devDependencies: ["@edgedb/generate"],
78
78
  dependencies: ["edgedb"]
79
79
  });
@@ -75,7 +75,7 @@ async function getPackageJson(props) {
75
75
  precedence: 0
76
76
  }
77
77
  });
78
- return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
78
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
79
79
  devDependencies: ["eslint", "@typescript-eslint/parser", "@typescript-eslint/eslint-plugin"]
80
80
  });
81
81
  }
@@ -51,7 +51,9 @@ var require_package = __commonJS({
51
51
  "@types/express": "^4.17.21",
52
52
  "@types/node": "^18.19.14",
53
53
  "cookie-parser": "^1.4.6",
54
+ dotenv: "^16.4.5",
54
55
  express: "^4.19.2",
56
+ "express-openid-connect": "^2.17.1",
55
57
  "firebase-admin": "^12.0.0",
56
58
  telefunc: "^0.1.71",
57
59
  tsx: "^4.7.2",
@@ -106,10 +108,11 @@ async function getPackageJson(props) {
106
108
  precedence: 20
107
109
  }
108
110
  });
109
- return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
111
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
110
112
  devDependencies: [
111
113
  "@types/express",
112
- ...props.meta.BATI.has("firebase-auth") ? ["@types/cookie-parser"] : []
114
+ ...props.meta.BATI.has("firebase-auth") ? ["@types/cookie-parser"] : [],
115
+ ...props.meta.BATI.has("auth0") ? ["dotenv"] : []
113
116
  ],
114
117
  dependencies: [
115
118
  "@hattip/adapter-node",
@@ -118,7 +121,8 @@ async function getPackageJson(props) {
118
121
  "vite",
119
122
  "vike",
120
123
  ...props.meta.BATI.has("authjs") ? ["@auth/core", "vike-authjs"] : [],
121
- ...props.meta.BATI.has("firebase-auth") ? ["cookie-parser"] : []
124
+ ...props.meta.BATI.has("firebase-auth") ? ["cookie-parser"] : [],
125
+ ...props.meta.BATI.has("auth0") ? ["express-openid-connect"] : []
122
126
  ]
123
127
  });
124
128
  }
@@ -1,3 +1,5 @@
1
+ // BATI.has("auth0")
2
+ import "dotenv/config";
1
3
  import { dirname } from "node:path";
2
4
  import { fileURLToPath } from "node:url";
3
5
  import CredentialsProvider from "@auth/core/providers/credentials";
@@ -7,6 +9,7 @@ import { createMiddleware } from "@hattip/adapter-node";
7
9
  import * as trpcExpress from "@trpc/server/adapters/express";
8
10
  import cookieParser from "cookie-parser";
9
11
  import express, { type Request } from "express";
12
+ import { auth, type ConfigParams } from "express-openid-connect";
10
13
  import { getAuth } from "firebase-admin/auth";
11
14
  import { telefunc } from "telefunc";
12
15
  import { VikeAuth } from "vike-authjs";
@@ -16,6 +19,8 @@ const __filename = fileURLToPath(import.meta.url);
16
19
  const __dirname = dirname(__filename);
17
20
  const isProduction = process.env.NODE_ENV === "production";
18
21
  const root = __dirname;
22
+ const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
23
+ const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678;
19
24
 
20
25
  startServer();
21
26
 
@@ -32,7 +37,7 @@ async function startServer() {
32
37
  const viteDevMiddleware = (
33
38
  await vite.createServer({
34
39
  root,
35
- server: { middlewareMode: true },
40
+ server: { middlewareMode: true, hmr: { port: hmrPort } },
36
41
  })
37
42
  ).middlewares;
38
43
  app.use(viteDevMiddleware);
@@ -88,7 +93,7 @@ async function startServer() {
88
93
  const user = await auth.getUser(decodedIdToken.sub);
89
94
  req.user = user;
90
95
  } catch (error) {
91
- console.error("verifySessionCookie:", error);
96
+ console.debug("verifySessionCookie:", error);
92
97
  req.user = null;
93
98
  }
94
99
 
@@ -123,6 +128,21 @@ async function startServer() {
123
128
  });
124
129
  }
125
130
 
131
+ if (BATI.has("auth0")) {
132
+ const config: ConfigParams = {
133
+ authRequired: false, // Controls whether authentication is required for all routes
134
+ auth0Logout: true, // Uses Auth0 logout feature
135
+ baseURL: process.env.BASE_URL?.startsWith("http") ? process.env.BASE_URL : `http://localhost:${port}`, // The URL where the application is served
136
+ routes: {
137
+ login: "/api/auth/login", // Custom login route, default is : "/login"
138
+ logout: "/api/auth/logout", // Custom logout route, default is : "/logout"
139
+ callback: "/api/auth/callback", // Custom callback route, default is "/callback"
140
+ },
141
+ };
142
+
143
+ app.use(auth(config));
144
+ }
145
+
126
146
  if (BATI.has("trpc")) {
127
147
  /**
128
148
  * tRPC route
@@ -177,24 +197,26 @@ async function startServer() {
177
197
  * @link {@see https://vike.dev}
178
198
  **/
179
199
  app.all("*", async (req: Request, res, next) => {
180
- const pageContextInit = BATI.has("firebase-auth")
181
- ? { urlOriginal: req.originalUrl, user: req.user }
182
- : { urlOriginal: req.originalUrl };
200
+ const pageContextInit = BATI.has("auth0")
201
+ ? { urlOriginal: req.originalUrl, user: req.oidc.user }
202
+ : BATI.has("firebase-auth")
203
+ ? { urlOriginal: req.originalUrl, user: req.user }
204
+ : { urlOriginal: req.originalUrl };
183
205
 
184
206
  const pageContext = await renderPage(pageContextInit);
185
- const { httpResponse } = pageContext
207
+ const { httpResponse } = pageContext;
186
208
 
187
209
  if (!httpResponse) {
188
- return next()
210
+ return next();
189
211
  } else {
190
212
  const { statusCode, headers } = httpResponse;
191
- headers.forEach(([name, value]) => res.setHeader(name, value))
192
- res.status(statusCode)
213
+ headers.forEach(([name, value]) => res.setHeader(name, value));
214
+ res.status(statusCode);
193
215
  httpResponse.pipe(res);
194
216
  }
195
217
  });
196
218
 
197
- app.listen(process.env.PORT ? parseInt(process.env.PORT) : 3000, () => {
198
- console.log("Server listening on http://localhost:3000");
219
+ app.listen(port, () => {
220
+ console.log(`Server listening on http://localhost:${port}`);
199
221
  });
200
222
  }
@@ -0,0 +1,10 @@
1
+ import type { UserRecord } from "firebase-admin/auth";
2
+
3
+ //# BATI.has("firebase-auth")
4
+ declare module "express" {
5
+ interface Request {
6
+ user?: UserRecord | null;
7
+ }
8
+ }
9
+
10
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ import "dotenv/config";
@@ -62,9 +62,6 @@ var require_package = __commonJS({
62
62
  }
63
63
  },
64
64
  exports: {
65
- "./types": {
66
- types: "./dist/types/types.d.ts"
67
- },
68
65
  "./libs/firebaseAdmin": {
69
66
  types: "./dist/types/libs/firebaseAdmin.d.ts"
70
67
  },
@@ -83,9 +80,6 @@ var require_package = __commonJS({
83
80
  },
84
81
  typesVersions: {
85
82
  "*": {
86
- types: [
87
- "./dist/types/types.d.ts"
88
- ],
89
83
  "libs/firebaseAdmin": [
90
84
  "./dist/types/libs/firebaseAdmin.d.ts"
91
85
  ],
@@ -111,7 +105,7 @@ var require_package = __commonJS({
111
105
  import { addDependency, loadAsJson } from "@batijs/core";
112
106
  async function getPackageJson(props) {
113
107
  const packageJson = await loadAsJson(props);
114
- return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
108
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
115
109
  devDependencies: ["dotenv"],
116
110
  dependencies: ["firebase", "firebase-admin", "firebaseui"]
117
111
  });
@@ -0,0 +1,20 @@
1
+ // files/firebase/$service-account.json.ts
2
+ async function getPackageJson() {
3
+ const firebaseAccountStringified = process.env.TEST_FIREBASE_ACCOUNT;
4
+ return firebaseAccountStringified ? JSON.parse(firebaseAccountStringified) : {
5
+ type: "",
6
+ project_id: "",
7
+ private_key_id: "",
8
+ private_key: "",
9
+ client_email: "",
10
+ client_id: "",
11
+ auth_uri: "",
12
+ token_uri: "",
13
+ auth_provider_x509_cert_url: "",
14
+ client_x509_cert_url: "",
15
+ universe_domain: ""
16
+ };
17
+ }
18
+ export {
19
+ getPackageJson as default
20
+ };
@@ -1,14 +1,14 @@
1
1
  import "dotenv/config";
2
- import { getApps, type App, initializeApp, applicationDefault, getApp } from "firebase-admin/app";
2
+ import { applicationDefault, getApp, getApps, initializeApp, type App } from "firebase-admin/app";
3
3
 
4
4
  let firebaseAdmin: App | undefined;
5
5
 
6
6
  if (!getApps().length) {
7
- firebaseAdmin = initializeApp({
8
- credential: applicationDefault(),
9
- });
7
+ firebaseAdmin = initializeApp({
8
+ credential: applicationDefault(),
9
+ });
10
10
  } else {
11
- firebaseAdmin = getApp();
11
+ firebaseAdmin = getApp();
12
12
  }
13
13
 
14
- export { firebaseAdmin }
14
+ export { firebaseAdmin };
@@ -1,31 +1,31 @@
1
- import firebase from "firebase/compat/app"
2
- import type { UserCredential } from "firebase/auth"
3
- import * as firebaseui from "firebaseui"
1
+ import type { UserCredential } from "firebase/auth";
2
+ import firebase from "firebase/compat/app";
3
+ import * as firebaseui from "firebaseui";
4
4
 
5
- type SessionLogin = (authResult: UserCredential) => Promise<void>
5
+ type SessionLogin = (authResult: UserCredential) => Promise<void>;
6
6
 
7
7
  function startFirebaseUI(ui: firebaseui.auth.AuthUI, sessionLogin?: SessionLogin) {
8
- // Please read firebaseui docs at https://github.com/firebase/firebaseui-web
9
- const uiCOnfig = {
10
- callbacks: {
11
- signInSuccessWithAuthResult(authResult: UserCredential) {
12
- if (sessionLogin) {
13
- sessionLogin(authResult)
14
- // Don't redirect after firebase client successfully sign-in, let vike handle the rest.
15
- return false
16
- }
17
- return true
18
- }
19
- },
20
- signInFlow: "popup",
21
- signInOptions: [
22
- // Disable "Email enumeration protection" to be able to login with registered email address
23
- // https://console.firebase.google.com/u/1/project/{project-id}/authentication/settings
24
- firebase.auth.EmailAuthProvider.PROVIDER_ID,
25
- firebase.auth.GoogleAuthProvider.PROVIDER_ID,
26
- ],
27
- }
28
- return ui.start("#firebaseui-auth-container", uiCOnfig)
8
+ // Please read firebaseui docs at https://github.com/firebase/firebaseui-web
9
+ const uiCOnfig = {
10
+ callbacks: {
11
+ signInSuccessWithAuthResult(authResult: UserCredential) {
12
+ if (sessionLogin) {
13
+ sessionLogin(authResult);
14
+ // Don't redirect after firebase client successfully sign-in, let vike handle the rest.
15
+ return false;
16
+ }
17
+ return true;
18
+ },
19
+ },
20
+ signInFlow: "popup",
21
+ signInOptions: [
22
+ // Disable "Email enumeration protection" to be able to login with registered email address
23
+ // https://console.firebase.google.com/u/1/project/{project-id}/authentication/settings
24
+ firebase.auth.EmailAuthProvider.PROVIDER_ID,
25
+ firebase.auth.GoogleAuthProvider.PROVIDER_ID,
26
+ ],
27
+ };
28
+ return ui.start("#firebaseui-auth-container", uiCOnfig);
29
29
  }
30
30
 
31
- export { startFirebaseUI }
31
+ export { startFirebaseUI };
@@ -2,7 +2,8 @@
2
2
  import { deleteApp, getApp, getApps, initializeApp, type FirebaseApp } from "firebase/app";
3
3
  import { getAuth, inMemoryPersistence } from "firebase/auth";
4
4
 
5
- // Your web app's Firebase configuration
5
+ // TODO: Fill your web app's Firebase configuration
6
+ // See https://firebase.google.com/docs/web/learn-more?hl=fr#config-object
6
7
  const firebaseConfig = {
7
8
  apiKey: "",
8
9
  authDomain: "",
@@ -1,11 +1,11 @@
1
1
  // https://vike.dev/guard
2
- import { redirect } from 'vike/abort'
3
- import type { GuardAsync } from 'vike/types'
2
+ import { redirect } from "vike/abort";
3
+ import type { GuardAsync } from "vike/types";
4
4
 
5
5
  const guard: GuardAsync = async (pageContext): ReturnType<GuardAsync> => {
6
6
  if (pageContext.user) {
7
- throw redirect('/')
7
+ throw redirect("/");
8
8
  }
9
- }
9
+ };
10
10
 
11
- export { guard }
11
+ export { guard };
@@ -2,14 +2,6 @@ import type { UserRecord } from "firebase-admin/auth";
2
2
  import type { FirebaseApp } from "firebase/app";
3
3
 
4
4
  declare global {
5
- /*{ @if (it.BATI.has("express")) }*/
6
- // eslint-disable-next-line
7
- namespace Express {
8
- interface Request {
9
- user?: UserRecord | null;
10
- }
11
- }
12
- /*{ /if }*/
13
5
  // eslint-disable-next-line
14
6
  namespace Vike {
15
7
  interface PageContext {
@@ -21,5 +13,4 @@ declare global {
21
13
  }
22
14
  }
23
15
 
24
- // Tell TypeScript that this file isn't an ambient module
25
16
  export {};
@@ -1,3 +1,3 @@
1
- import type { GuardAsync } from 'vike/types';
1
+ import type { GuardAsync } from "vike/types";
2
2
  declare const guard: GuardAsync;
3
3
  export { guard };
@@ -47,8 +47,12 @@ var require_package = __commonJS({
47
47
  "@batijs/trpc": "workspace:^",
48
48
  "@hattip/polyfills": "^0.0.45",
49
49
  "@trpc/server": "^10.45.2",
50
+ "@types/express": "^4.17.21",
50
51
  "@types/node": "^18.19.14",
51
52
  "@types/serve-static": "^1.15.7",
53
+ dotenv: "^16.4.5",
54
+ express: "^4.19.2",
55
+ "express-openid-connect": "^2.17.1",
52
56
  "firebase-admin": "^12.0.0",
53
57
  h3: "~1.11.1",
54
58
  "serve-static": "^1.15.0",
@@ -105,8 +109,11 @@ async function getPackageJson(props) {
105
109
  precedence: 20
106
110
  }
107
111
  });
108
- return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
109
- devDependencies: ["@types/serve-static"],
112
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
113
+ devDependencies: [
114
+ "@types/serve-static",
115
+ ...props.meta.BATI.has("auth0") ? ["@types/express", "dotenv"] : []
116
+ ],
110
117
  dependencies: [
111
118
  "@hattip/polyfills",
112
119
  "h3",
@@ -114,7 +121,8 @@ async function getPackageJson(props) {
114
121
  "tsx",
115
122
  "vike",
116
123
  "vite",
117
- ...props.meta.BATI.has("authjs") ? ["@auth/core", "vike-authjs"] : []
124
+ ...props.meta.BATI.has("authjs") ? ["@auth/core", "vike-authjs"] : [],
125
+ ...props.meta.BATI.has("auth0") ? ["express", "express-openid-connect"] : []
118
126
  ]
119
127
  });
120
128
  }
@@ -1,3 +1,5 @@
1
+ // BATI.has("auth0")
2
+ import "dotenv/config";
1
3
  import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
2
4
  import { dirname } from "node:path";
3
5
  import { fileURLToPath } from "node:url";
@@ -8,7 +10,9 @@ import installCrypto from "@hattip/polyfills/crypto";
8
10
  import installGetSetCookie from "@hattip/polyfills/get-set-cookie";
9
11
  import installWhatwgNodeFetch from "@hattip/polyfills/whatwg-node";
10
12
  import { nodeHTTPRequestHandler, type NodeHTTPCreateContextFnOptions } from "@trpc/server/adapters/node-http";
11
- import { getAuth, type UserRecord } from "firebase-admin/auth";
13
+ import express from "express";
14
+ import { auth, type ConfigParams } from "express-openid-connect";
15
+ import { getAuth } from "firebase-admin/auth";
12
16
  import {
13
17
  createApp,
14
18
  createRouter,
@@ -38,14 +42,8 @@ const __filename = fileURLToPath(import.meta.url);
38
42
  const __dirname = dirname(__filename);
39
43
  const isProduction = process.env.NODE_ENV === "production";
40
44
  const root = __dirname;
41
-
42
- /*{ @if (it.BATI.has("firebase-auth")) }*/
43
- declare module "h3" {
44
- interface H3EventContext {
45
- user: UserRecord | null;
46
- }
47
- }
48
- /*{ /if }*/
45
+ const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
46
+ const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678;
49
47
 
50
48
  startServer();
51
49
 
@@ -62,7 +60,7 @@ async function startServer() {
62
60
  const viteDevMiddleware = (
63
61
  await vite.createServer({
64
62
  root,
65
- server: { middlewareMode: true },
63
+ server: { middlewareMode: true, hmr: { port: hmrPort } },
66
64
  })
67
65
  ).middlewares;
68
66
  app.use(fromNodeMiddleware(viteDevMiddleware));
@@ -122,7 +120,7 @@ async function startServer() {
122
120
  const user = await auth.getUser(decodedIdToken.sub);
123
121
  event.context.user = user;
124
122
  } catch (error) {
125
- console.error("verifySessionCookie:", error);
123
+ console.debug("verifySessionCookie:", error);
126
124
  event.context.user = null;
127
125
  }
128
126
  }
@@ -176,6 +174,23 @@ async function startServer() {
176
174
  );
177
175
  }
178
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))));
192
+ }
193
+
179
194
  if (BATI.has("trpc")) {
180
195
  /**
181
196
  * tRPC route
@@ -234,12 +249,18 @@ async function startServer() {
234
249
  router.use(
235
250
  "/**",
236
251
  eventHandler(async (event) => {
237
- const pageContextInit = BATI.has("firebase-auth")
252
+ const pageContextInit = BATI.has("auth0")
238
253
  ? {
239
254
  urlOriginal: event.node.req.originalUrl || event.node.req.url!,
240
- user: event.context.user,
255
+ user: event.node.req.oidc.user,
241
256
  }
242
- : { urlOriginal: event.node.req.originalUrl || event.node.req.url! };
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
+
243
264
  const pageContext = await renderPage(pageContextInit);
244
265
  const response = pageContext.httpResponse;
245
266
 
@@ -252,9 +273,9 @@ async function startServer() {
252
273
 
253
274
  app.use(router);
254
275
 
255
- const server = createServer(toNodeListener(app)).listen(process.env.PORT || 3000);
276
+ const server = createServer(toNodeListener(app)).listen(port);
256
277
 
257
278
  server.on("listening", () => {
258
- console.log(`Server listening on http://localhost:${process.env.PORT || 3000}`);
279
+ console.log(`Server listening on http://localhost:${port}`);
259
280
  });
260
281
  }
@@ -0,0 +1,22 @@
1
+ import type { RequestContext, ResponseContext } from "express-openid-connect";
2
+ import type { UserRecord } from "firebase-admin/auth";
3
+
4
+ //# BATI.has("auth0")
5
+ declare module "node:http" {
6
+ interface IncomingMessage {
7
+ oidc: RequestContext;
8
+ }
9
+
10
+ interface ServerResponse {
11
+ oidc: ResponseContext;
12
+ }
13
+ }
14
+
15
+ //# BATI.has("firebase-auth")
16
+ declare module "h3" {
17
+ interface H3EventContext {
18
+ user: UserRecord | null;
19
+ }
20
+ }
21
+
22
+ export {};
@@ -1,6 +1 @@
1
- import { type UserRecord } from "firebase-admin/auth";
2
- declare module "h3" {
3
- interface H3EventContext {
4
- user: UserRecord | null;
5
- }
6
- }
1
+ import "dotenv/config";
@@ -102,7 +102,7 @@ async function getPackageJson(props) {
102
102
  if (packageJson.scripts.preview) {
103
103
  delete packageJson.scripts.preview;
104
104
  }
105
- return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
105
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
106
106
  devDependencies: ["@hattip/vite", "@hattip/adapter-node"],
107
107
  dependencies: [
108
108
  "@hattip/core",
@@ -65,7 +65,7 @@ var require_package = __commonJS({
65
65
  import { addDependency, loadAsJson } from "@batijs/core";
66
66
  async function getPackageJson(props) {
67
67
  const packageJson = await loadAsJson(props);
68
- return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
68
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
69
69
  devDependencies: ["prettier", "eslint-config-prettier"]
70
70
  });
71
71
  }
@@ -68,7 +68,7 @@ async function getPackageJson(props) {
68
68
  const packageJson = await loadAsJson(props);
69
69
  packageJson.scripts["prisma:studio"] = "prisma studio";
70
70
  packageJson.scripts["prisma:generate"] = "prisma generate";
71
- return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
71
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
72
72
  devDependencies: ["prisma"],
73
73
  dependencies: ["@prisma/client"]
74
74
  });