Skip to content

Commit 04c1972

Browse files
committed
feat: add firebase app check
1 parent b5a8952 commit 04c1972

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-firebase-project-id
55
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-firebase-storage-bucket
66
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your-firebase-messaging-sender-id
77
NEXT_PUBLIC_FIREBASE_APP_ID=your-firebase-app-id
8+
NEXT_PUBLIC_FIREBASE_APP_CHECK_KEY=your-firebase-app-check-site-key
89

910
# LINE LIFF Config
1011
NEXT_PUBLIC_LINE_LIFF_ID=your-line-liff-id

.github/workflows/web-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: ${{ secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET }}
4242
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID }}
4343
NEXT_PUBLIC_FIREBASE_APP_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_APP_ID }}
44+
NEXT_PUBLIC_FIREBASE_APP_CHECK_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_APP_CHECK_KEY }}
4445
NEXT_PUBLIC_LINE_LIFF_ID: ${{ secrets.NEXT_PUBLIC_LINE_LIFF_ID }}
4546

4647
- uses: FirebaseExtended/action-hosting-deploy@v0.9.0

src/app/not-found.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use client";
2+
import Link from "next/link";
3+
4+
export default function NotFound() {
5+
return (
6+
<div>
7+
<h2>Not Found</h2>
8+
<p>Could not find requested resource</p>
9+
<Link href="/">Return Home</Link>
10+
</div>
11+
);
12+
}

src/lib/firebase.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
DocumentData,
1515
} from "firebase/firestore";
1616
import { getFunctions, httpsCallable } from "firebase/functions";
17+
import { initializeAppCheck, ReCaptchaV3Provider } from "firebase/app-check";
1718
import type {
1819
AuthenticateLineUserParams,
1920
AuthenticateLineUserResult,
@@ -32,6 +33,19 @@ const firebaseConfig = {
3233
// Initialize Firebase
3334
const app =
3435
getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0];
36+
37+
if (process.env.NEXT_PUBLIC_FIREBASE_APP_CHECK_KEY) {
38+
initializeAppCheck(app, {
39+
provider: new ReCaptchaV3Provider(
40+
process.env.NEXT_PUBLIC_FIREBASE_APP_CHECK_KEY
41+
),
42+
43+
// Optional argument. If true, the SDK automatically refreshes App Check
44+
// tokens as needed.
45+
isTokenAutoRefreshEnabled: true,
46+
});
47+
}
48+
3549
const auth = getAuth(app);
3650
const db = getFirestore(app);
3751
const functions = getFunctions(app, "asia-southeast1");

0 commit comments

Comments
 (0)