Skip to content

Commit cbcb0fa

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

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-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/lib/firebase.ts

Lines changed: 17 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,22 @@ const firebaseConfig = {
3233
// Initialize Firebase
3334
const app =
3435
getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0];
36+
37+
if (
38+
typeof document !== "undefined" &&
39+
process.env.NEXT_PUBLIC_FIREBASE_APP_CHECK_KEY
40+
) {
41+
initializeAppCheck(app, {
42+
provider: new ReCaptchaV3Provider(
43+
process.env.NEXT_PUBLIC_FIREBASE_APP_CHECK_KEY
44+
),
45+
46+
// Optional argument. If true, the SDK automatically refreshes App Check
47+
// tokens as needed.
48+
isTokenAutoRefreshEnabled: true,
49+
});
50+
}
51+
3552
const auth = getAuth(app);
3653
const db = getFirestore(app);
3754
const functions = getFunctions(app, "asia-southeast1");

0 commit comments

Comments
 (0)