@batijs/cli 0.0.164 → 0.0.165
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/compiled/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/eslint/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/express/files/$package.json.js +12 -4
- package/dist/boilerplates/@batijs/express/files/express-entry.ts +64 -7
- package/dist/boilerplates/@batijs/firebase-auth/files/$.env.js +15 -0
- package/dist/boilerplates/@batijs/firebase-auth/files/$README.md.js +30 -0
- package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +121 -0
- package/dist/boilerplates/@batijs/firebase-auth/files/firebase/service-account-example.json +13 -0
- package/dist/boilerplates/@batijs/firebase-auth/files/libs/firebaseAdmin.ts +14 -0
- package/dist/boilerplates/@batijs/firebase-auth/files/libs/firebaseUI.ts +31 -0
- package/dist/boilerplates/@batijs/firebase-auth/files/pages/+firebaseApp.ts +32 -0
- package/dist/boilerplates/@batijs/firebase-auth/files/pages/login/+config.ts +6 -0
- package/dist/boilerplates/@batijs/firebase-auth/files/pages/login/+guard.ts +11 -0
- package/dist/boilerplates/@batijs/firebase-auth/files/types.ts +25 -0
- package/dist/boilerplates/@batijs/firebase-auth/types/libs/firebaseAdmin.d.ts +4 -0
- package/dist/boilerplates/@batijs/firebase-auth/types/libs/firebaseUI.d.ts +5 -0
- package/dist/boilerplates/@batijs/firebase-auth/types/pages/+firebaseApp.d.ts +3 -0
- package/dist/boilerplates/@batijs/firebase-auth/types/pages/login/+config.d.ts +4 -0
- package/dist/boilerplates/@batijs/firebase-auth/types/pages/login/+guard.d.ts +3 -0
- package/dist/boilerplates/@batijs/firebase-auth/types/types.d.ts +18 -0
- package/dist/boilerplates/@batijs/h3/files/$package.json.js +4 -2
- package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +87 -1
- package/dist/boilerplates/@batijs/h3/types/h3-entry.d.ts +6 -1
- package/dist/boilerplates/@batijs/hattip/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/prettier/files/.prettierignore +3 -0
- package/dist/boilerplates/@batijs/react/files/$package.json.js +4 -4
- package/dist/boilerplates/@batijs/react/files/pages/+config.ts +11 -0
- package/dist/boilerplates/@batijs/react/types/pages/+config.d.ts +8 -0
- package/dist/boilerplates/@batijs/react-firebase-auth/files/pages/login/+Page.tsx +52 -0
- package/dist/boilerplates/@batijs/react-firebase-auth/types/pages/login/+Page.d.ts +3 -0
- package/dist/boilerplates/@batijs/solid/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/solid/files/pages/+config.ts +11 -0
- package/dist/boilerplates/@batijs/solid/types/pages/+config.d.ts +8 -0
- package/dist/boilerplates/@batijs/solid-firebase-auth/files/pages/login/+Page.tsx +52 -0
- package/dist/boilerplates/@batijs/solid-firebase-auth/types/pages/login/+Page.d.ts +3 -0
- package/dist/boilerplates/@batijs/tailwindcss/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/trpc/files/$package.json.js +3 -3
- package/dist/boilerplates/@batijs/trpc/types/trpc/client.d.ts +72 -38
- package/dist/boilerplates/@batijs/vercel/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/vue/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/vue/files/pages/+config.ts +11 -0
- package/dist/boilerplates/@batijs/vue/types/pages/+config.d.ts +8 -0
- package/dist/boilerplates/@batijs/vue-firebase-auth/files/pages/login/+Page.vue +51 -0
- package/dist/boilerplates/boilerplates.json +59 -0
- package/dist/index.js +3 -3
- package/package.json +7 -7
|
@@ -43,12 +43,12 @@ var require_package = __commonJS({
|
|
|
43
43
|
devDependencies: {
|
|
44
44
|
"@batijs/compile": "workspace:*",
|
|
45
45
|
"@types/node": "^18.19.14",
|
|
46
|
-
vite: "^5.1.
|
|
46
|
+
vite: "^5.1.6",
|
|
47
47
|
"vite-plugin-compiled-react": "^1.1.3"
|
|
48
48
|
},
|
|
49
49
|
dependencies: {
|
|
50
50
|
"@batijs/core": "workspace:*",
|
|
51
|
-
"@compiled/react": "^0.
|
|
51
|
+
"@compiled/react": "^0.17.0"
|
|
52
52
|
},
|
|
53
53
|
files: [
|
|
54
54
|
"dist/"
|
|
@@ -42,8 +42,8 @@ var require_package = __commonJS({
|
|
|
42
42
|
},
|
|
43
43
|
devDependencies: {
|
|
44
44
|
"@batijs/compile": "workspace:^",
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^7.1.
|
|
46
|
-
"@typescript-eslint/parser": "^7.1.
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^7.1.1",
|
|
46
|
+
"@typescript-eslint/parser": "^7.1.1",
|
|
47
47
|
eslint: "^8.57.0"
|
|
48
48
|
},
|
|
49
49
|
dependencies: {
|
|
@@ -43,17 +43,21 @@ var require_package = __commonJS({
|
|
|
43
43
|
devDependencies: {
|
|
44
44
|
"@auth/core": "^0.28.0",
|
|
45
45
|
"@batijs/compile": "workspace:*",
|
|
46
|
+
"@batijs/firebase-auth": "workspace:*",
|
|
46
47
|
"@batijs/trpc": "workspace:*",
|
|
47
48
|
"@hattip/adapter-node": "^0.0.43",
|
|
48
|
-
"@trpc/server": "^10.45.
|
|
49
|
+
"@trpc/server": "^10.45.2",
|
|
50
|
+
"@types/cookie-parser": "^1.4.6",
|
|
49
51
|
"@types/express": "^4.17.21",
|
|
50
52
|
"@types/node": "^18.19.14",
|
|
53
|
+
"cookie-parser": "^1.4.6",
|
|
51
54
|
express: "^4.18.3",
|
|
55
|
+
"firebase-admin": "^12.0.0",
|
|
52
56
|
telefunc: "^0.1.71",
|
|
53
57
|
tsx: "^4.7.1",
|
|
54
58
|
vike: "^0.4.165",
|
|
55
59
|
"vike-authjs": "^0.1.5",
|
|
56
|
-
vite: "^5.1.
|
|
60
|
+
vite: "^5.1.6"
|
|
57
61
|
},
|
|
58
62
|
dependencies: {
|
|
59
63
|
"@batijs/core": "workspace:*"
|
|
@@ -103,14 +107,18 @@ async function getPackageJson(props) {
|
|
|
103
107
|
}
|
|
104
108
|
});
|
|
105
109
|
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
|
|
106
|
-
devDependencies: [
|
|
110
|
+
devDependencies: [
|
|
111
|
+
"@types/express",
|
|
112
|
+
...props.meta.BATI.has("firebase-auth") ? ["@types/cookie-parser"] : []
|
|
113
|
+
],
|
|
107
114
|
dependencies: [
|
|
108
115
|
"@hattip/adapter-node",
|
|
109
116
|
"express",
|
|
110
117
|
"tsx",
|
|
111
118
|
"vite",
|
|
112
119
|
"vike",
|
|
113
|
-
...props.meta.BATI.has("authjs") ? ["@auth/core", "vike-authjs"] : []
|
|
120
|
+
...props.meta.BATI.has("authjs") ? ["@auth/core", "vike-authjs"] : [],
|
|
121
|
+
...props.meta.BATI.has("firebase-auth") ? ["cookie-parser"] : []
|
|
114
122
|
]
|
|
115
123
|
});
|
|
116
124
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { dirname } from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import CredentialsProvider from "@auth/core/providers/credentials";
|
|
4
|
+
import { firebaseAdmin } from "@batijs/firebase-auth/libs/firebaseAdmin";
|
|
4
5
|
import { appRouter } from "@batijs/trpc/trpc/server";
|
|
5
6
|
import { createMiddleware } from "@hattip/adapter-node";
|
|
6
7
|
import * as trpcExpress from "@trpc/server/adapters/express";
|
|
7
|
-
import
|
|
8
|
+
import cookieParser from "cookie-parser";
|
|
9
|
+
import express, { type Request } from "express";
|
|
10
|
+
import { getAuth } from "firebase-admin/auth";
|
|
8
11
|
import { telefunc } from "telefunc";
|
|
9
12
|
import { VikeAuth } from "vike-authjs";
|
|
10
13
|
import { renderPage } from "vike/server";
|
|
@@ -74,6 +77,52 @@ async function startServer() {
|
|
|
74
77
|
);
|
|
75
78
|
}
|
|
76
79
|
|
|
80
|
+
if (BATI.has("firebase-auth")) {
|
|
81
|
+
app.use(cookieParser());
|
|
82
|
+
app.use(async function (req: Request, _, next) {
|
|
83
|
+
const sessionCookie: string = req.cookies.__session || "";
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const auth = getAuth(firebaseAdmin);
|
|
87
|
+
const decodedIdToken = await auth.verifySessionCookie(sessionCookie, true);
|
|
88
|
+
const user = await auth.getUser(decodedIdToken.sub);
|
|
89
|
+
req.user = user;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error("verifySessionCookie:", error);
|
|
92
|
+
req.user = null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
next();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
app.use(express.json()); // Parse & make HTTP request body available at `req.body`
|
|
99
|
+
app.post("/api/sessionLogin", (req: Request, res) => {
|
|
100
|
+
const idToken: string = req.body.idToken || "";
|
|
101
|
+
|
|
102
|
+
const expiresIn = 60 * 60 * 24 * 5 * 1000; // 5 days
|
|
103
|
+
|
|
104
|
+
getAuth(firebaseAdmin)
|
|
105
|
+
.createSessionCookie(idToken, { expiresIn })
|
|
106
|
+
.then(
|
|
107
|
+
(sessionCookie) => {
|
|
108
|
+
// Set cookie policy for session cookie.
|
|
109
|
+
const options = { maxAge: expiresIn, httpOnly: true, secure: true };
|
|
110
|
+
res.cookie("__session", sessionCookie, options);
|
|
111
|
+
res.end(JSON.stringify({ status: "success" }));
|
|
112
|
+
},
|
|
113
|
+
(error) => {
|
|
114
|
+
console.error("createSessionCookie:", error);
|
|
115
|
+
res.status(401).send("Unauthorized Request");
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
app.post("/api/sessionLogout", function (_, res) {
|
|
121
|
+
res.clearCookie("__session");
|
|
122
|
+
res.end();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
77
126
|
if (BATI.has("trpc")) {
|
|
78
127
|
/**
|
|
79
128
|
* tRPC route
|
|
@@ -127,14 +176,22 @@ async function startServer() {
|
|
|
127
176
|
*
|
|
128
177
|
* @link {@see https://vike.dev}
|
|
129
178
|
**/
|
|
130
|
-
app.all("*", async (req, res, next) => {
|
|
131
|
-
const pageContextInit =
|
|
179
|
+
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 };
|
|
183
|
+
|
|
132
184
|
const pageContext = await renderPage(pageContextInit);
|
|
133
|
-
|
|
185
|
+
const { httpResponse } = pageContext
|
|
134
186
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
187
|
+
if (!httpResponse) {
|
|
188
|
+
return next()
|
|
189
|
+
} else {
|
|
190
|
+
const { statusCode, headers } = httpResponse;
|
|
191
|
+
headers.forEach(([name, value]) => res.setHeader(name, value))
|
|
192
|
+
res.status(statusCode)
|
|
193
|
+
httpResponse.pipe(res);
|
|
194
|
+
}
|
|
138
195
|
});
|
|
139
196
|
|
|
140
197
|
app.listen(process.env.PORT ? parseInt(process.env.PORT) : 3000, () => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// files/$.env.ts
|
|
2
|
+
import { appendToEnv } from "@batijs/core";
|
|
3
|
+
async function getEnv(props) {
|
|
4
|
+
const envContent = await props.readfile?.();
|
|
5
|
+
return appendToEnv(
|
|
6
|
+
envContent,
|
|
7
|
+
"GOOGLE_APPLICATION_CREDENTIALS",
|
|
8
|
+
"firebase/service-account.json",
|
|
9
|
+
`Location of Your Firebase service account (use for firebase-admin).
|
|
10
|
+
Download the file from https://console.firebase.google.com/u/0/project/{firebase-project-id}/settings/serviceaccounts/adminsdk`
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
getEnv as default
|
|
15
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
## *Firebase*
|
|
7
|
+
- You first need to **[Create a Firebase project](https://firebase.google.com/docs/web/setup#create-project)**.
|
|
8
|
+
- Then register your app in the firebase console. **[Register your app](https://firebase.google.com/docs/web/setup#register-app)**
|
|
9
|
+
- Copy Your web app's Firebase configuration and paste in \`/pages/+firebaseApp.ts\` Example :
|
|
10
|
+
\`\`\`ts
|
|
11
|
+
const firebaseConfig = {
|
|
12
|
+
apiKey: "",
|
|
13
|
+
authDomain: "",
|
|
14
|
+
projectId: "",
|
|
15
|
+
storageBucket: "",
|
|
16
|
+
messagingSenderId: "",
|
|
17
|
+
appId: "",
|
|
18
|
+
};
|
|
19
|
+
\`\`\`
|
|
20
|
+
- Download Your Firebase service account from [Your Firebase Project Settings > Service accounts](https://console.firebase.google.com/u/0/project/{firebase-project-id}/settings/serviceaccounts/adminsdk)
|
|
21
|
+
- Rename to service-account.json and move it to folder \`/firebase/\`.
|
|
22
|
+
- Read more about Firebase Auth at official [firebase auth docs](https://firebase.google.com/docs/auth)
|
|
23
|
+
- Read FirebaseUI at [firebaseui-web docs](https://github.com/firebase/firebaseui-web?tab=readme-ov-file#using-firebaseui-for-authentication)
|
|
24
|
+
`;
|
|
25
|
+
content.addTodo(todo);
|
|
26
|
+
return content.finalize();
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
getReadme as default
|
|
30
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
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/firebase-auth",
|
|
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
|
+
"@batijs/compile": "workspace:*",
|
|
45
|
+
"@types/node": "^18.19.14",
|
|
46
|
+
dotenv: "^16.4.4",
|
|
47
|
+
firebase: "^10.8.0",
|
|
48
|
+
"firebase-admin": "^12.0.0",
|
|
49
|
+
firebaseui: "^6.1.0",
|
|
50
|
+
vike: "^0.4.162",
|
|
51
|
+
vite: "^5.1.6"
|
|
52
|
+
},
|
|
53
|
+
dependencies: {
|
|
54
|
+
"@batijs/core": "workspace:*"
|
|
55
|
+
},
|
|
56
|
+
files: [
|
|
57
|
+
"dist/"
|
|
58
|
+
],
|
|
59
|
+
bati: {
|
|
60
|
+
if: {
|
|
61
|
+
flag: "firebase-auth"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
exports: {
|
|
65
|
+
"./types": {
|
|
66
|
+
types: "./dist/types/types.d.ts"
|
|
67
|
+
},
|
|
68
|
+
"./libs/firebaseAdmin": {
|
|
69
|
+
types: "./dist/types/libs/firebaseAdmin.d.ts"
|
|
70
|
+
},
|
|
71
|
+
"./libs/firebaseUI": {
|
|
72
|
+
types: "./dist/types/libs/firebaseUI.d.ts"
|
|
73
|
+
},
|
|
74
|
+
"./pages/+firebaseApp": {
|
|
75
|
+
types: "./dist/types/pages/+firebaseApp.d.ts"
|
|
76
|
+
},
|
|
77
|
+
"./pages/login/+config": {
|
|
78
|
+
types: "./dist/types/pages/login/+config.d.ts"
|
|
79
|
+
},
|
|
80
|
+
"./pages/login/+guard": {
|
|
81
|
+
types: "./dist/types/pages/login/+guard.d.ts"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
typesVersions: {
|
|
85
|
+
"*": {
|
|
86
|
+
types: [
|
|
87
|
+
"./dist/types/types.d.ts"
|
|
88
|
+
],
|
|
89
|
+
"libs/firebaseAdmin": [
|
|
90
|
+
"./dist/types/libs/firebaseAdmin.d.ts"
|
|
91
|
+
],
|
|
92
|
+
"libs/firebaseUI": [
|
|
93
|
+
"./dist/types/libs/firebaseUI.d.ts"
|
|
94
|
+
],
|
|
95
|
+
"pages/+firebaseApp": [
|
|
96
|
+
"./dist/types/pages/+firebaseApp.d.ts"
|
|
97
|
+
],
|
|
98
|
+
"pages/login/+config": [
|
|
99
|
+
"./dist/types/pages/login/+config.d.ts"
|
|
100
|
+
],
|
|
101
|
+
"pages/login/+guard": [
|
|
102
|
+
"./dist/types/pages/login/+guard.d.ts"
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// files/$package.json.ts
|
|
111
|
+
import { addDependency, loadAsJson } from "@batijs/core";
|
|
112
|
+
async function getPackageJson(props) {
|
|
113
|
+
const packageJson = await loadAsJson(props);
|
|
114
|
+
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
|
|
115
|
+
devDependencies: ["dotenv"],
|
|
116
|
+
dependencies: ["firebase", "firebase-admin", "firebaseui"]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
export {
|
|
120
|
+
getPackageJson as default
|
|
121
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "",
|
|
3
|
+
"project_id": "",
|
|
4
|
+
"private_key_id": "",
|
|
5
|
+
"private_key": "",
|
|
6
|
+
"client_email": "",
|
|
7
|
+
"client_id": "",
|
|
8
|
+
"auth_uri": "",
|
|
9
|
+
"token_uri": "",
|
|
10
|
+
"auth_provider_x509_cert_url": "",
|
|
11
|
+
"client_x509_cert_url": "",
|
|
12
|
+
"universe_domain": ""
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { getApps, type App, initializeApp, applicationDefault, getApp } from "firebase-admin/app";
|
|
3
|
+
|
|
4
|
+
let firebaseAdmin: App | undefined;
|
|
5
|
+
|
|
6
|
+
if (!getApps().length) {
|
|
7
|
+
firebaseAdmin = initializeApp({
|
|
8
|
+
credential: applicationDefault(),
|
|
9
|
+
});
|
|
10
|
+
} else {
|
|
11
|
+
firebaseAdmin = getApp();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { firebaseAdmin }
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import firebase from "firebase/compat/app"
|
|
2
|
+
import type { UserCredential } from "firebase/auth"
|
|
3
|
+
import * as firebaseui from "firebaseui"
|
|
4
|
+
|
|
5
|
+
type SessionLogin = (authResult: UserCredential) => Promise<void>
|
|
6
|
+
|
|
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)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { startFirebaseUI }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Import the functions you need from the SDKs you need
|
|
2
|
+
import { deleteApp, getApp, getApps, initializeApp, type FirebaseApp } from "firebase/app";
|
|
3
|
+
import { getAuth, inMemoryPersistence } from "firebase/auth";
|
|
4
|
+
|
|
5
|
+
// Your web app's Firebase configuration
|
|
6
|
+
const firebaseConfig = {
|
|
7
|
+
apiKey: "",
|
|
8
|
+
authDomain: "",
|
|
9
|
+
projectId: "",
|
|
10
|
+
storageBucket: "",
|
|
11
|
+
messagingSenderId: "",
|
|
12
|
+
appId: "",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
let firebaseApp: FirebaseApp | undefined;
|
|
16
|
+
// create a singleton client side firebaseApp
|
|
17
|
+
if (!getApps().length) {
|
|
18
|
+
firebaseApp = initializeApp(firebaseConfig);
|
|
19
|
+
} else {
|
|
20
|
+
firebaseApp = getApp();
|
|
21
|
+
deleteApp(firebaseApp);
|
|
22
|
+
firebaseApp = initializeApp(firebaseConfig);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const auth = getAuth(firebaseApp);
|
|
26
|
+
|
|
27
|
+
// As httpOnly cookies are to be used, do not persist any state client side.
|
|
28
|
+
// `inMemoryPersistence` is an implementation of Persistence of type 'NONE'.
|
|
29
|
+
auth.setPersistence(inMemoryPersistence);
|
|
30
|
+
|
|
31
|
+
// export the firebaseApp
|
|
32
|
+
export default firebaseApp;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// https://vike.dev/guard
|
|
2
|
+
import { redirect } from 'vike/abort'
|
|
3
|
+
import type { GuardAsync } from 'vike/types'
|
|
4
|
+
|
|
5
|
+
const guard: GuardAsync = async (pageContext): ReturnType<GuardAsync> => {
|
|
6
|
+
if (pageContext.user) {
|
|
7
|
+
throw redirect('/')
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { guard }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { UserRecord } from "firebase-admin/auth";
|
|
2
|
+
import type { FirebaseApp } from "firebase/app";
|
|
3
|
+
|
|
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
|
+
// eslint-disable-next-line
|
|
14
|
+
namespace Vike {
|
|
15
|
+
interface PageContext {
|
|
16
|
+
user?: UserRecord | null;
|
|
17
|
+
}
|
|
18
|
+
interface Config {
|
|
19
|
+
firebaseApp?: FirebaseApp;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Tell TypeScript that this file isn't an ambient module
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { UserCredential } from "firebase/auth";
|
|
2
|
+
import * as firebaseui from "firebaseui";
|
|
3
|
+
type SessionLogin = (authResult: UserCredential) => Promise<void>;
|
|
4
|
+
declare function startFirebaseUI(ui: firebaseui.auth.AuthUI, sessionLogin?: SessionLogin): void;
|
|
5
|
+
export { startFirebaseUI };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { UserRecord } from "firebase-admin/auth";
|
|
2
|
+
import type { FirebaseApp } from "firebase/app";
|
|
3
|
+
declare global {
|
|
4
|
+
namespace Express {
|
|
5
|
+
interface Request {
|
|
6
|
+
user?: UserRecord | null;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
namespace Vike {
|
|
10
|
+
interface PageContext {
|
|
11
|
+
user?: UserRecord | null;
|
|
12
|
+
}
|
|
13
|
+
interface Config {
|
|
14
|
+
firebaseApp?: FirebaseApp;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -43,18 +43,20 @@ var require_package = __commonJS({
|
|
|
43
43
|
devDependencies: {
|
|
44
44
|
"@auth/core": "^0.28.0",
|
|
45
45
|
"@batijs/compile": "workspace:*",
|
|
46
|
+
"@batijs/firebase-auth": "workspace:*",
|
|
46
47
|
"@batijs/trpc": "workspace:^",
|
|
47
48
|
"@hattip/polyfills": "^0.0.43",
|
|
48
|
-
"@trpc/server": "^10.45.
|
|
49
|
+
"@trpc/server": "^10.45.2",
|
|
49
50
|
"@types/node": "^18.19.14",
|
|
50
51
|
"@types/serve-static": "^1.15.5",
|
|
52
|
+
"firebase-admin": "^12.0.0",
|
|
51
53
|
h3: "~1.11.1",
|
|
52
54
|
"serve-static": "^1.15.0",
|
|
53
55
|
telefunc: "^0.1.71",
|
|
54
56
|
tsx: "^4.7.1",
|
|
55
57
|
vike: "^0.4.165",
|
|
56
58
|
"vike-authjs": "^0.1.5",
|
|
57
|
-
vite: "^5.1.
|
|
59
|
+
vite: "^5.1.6"
|
|
58
60
|
},
|
|
59
61
|
dependencies: {
|
|
60
62
|
"@batijs/core": "workspace:*"
|