Skip to content

Commit 9a26642

Browse files
committed
feat: initialize Firebase for WasmJs web target
- Add `firebaseWeb` dependency version to `libs.versions.toml`. - Configure `app/web` to include the `firebase` NPM package for the `wasmJs` source set. - Implement `firebase.js` in resources to handle Firebase app initialization and optional Analytics support. - Integrate `initializeFirebase` into the `wasmJsMain` entry point using Kotlin's JS interop.
1 parent 230b647 commit 9a26642

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

app/web/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ kotlin {
4242
implementation(libs.koin.core)
4343
implementation(libs.koin.compose)
4444
implementation(libs.kermit)
45+
implementation(npm("firebase", libs.versions.firebaseWeb.get()))
4546
}
4647
resources.srcDir(layout.buildDirectory.dir("sqlite"))
4748
}

app/web/src/wasmJsMain/kotlin/com/softartdev/notedelight/main.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.koin.core.context.startKoin
1414

1515
fun main() {
1616
if (isKarmaTestRunner()) return
17+
initializeFirebase()
1718
Logger.setTag(DEFAULT_APP_LOG_TAG)
1819
startKoin {
1920
kermitLogger()
@@ -24,5 +25,8 @@ fun main() {
2425
}
2526
}
2627

28+
@JsModule("./firebase.js")
29+
private external fun initializeFirebase()
30+
2731
@JsFun("() => typeof window !== 'undefined' && window.__karma__ != null")
2832
private external fun isKarmaTestRunner(): Boolean
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { initializeApp } from "firebase/app";
2+
import { getAnalytics, isSupported } from "firebase/analytics";
3+
4+
const firebaseConfig = {
5+
apiKey: "AIzaSyB1Tx2XNQtH3rqM31PWRMHT9fd1Jfd56uc",
6+
authDomain: "noteroom-3ba13.firebaseapp.com",
7+
databaseURL: "https://noteroom-3ba13.firebaseio.com",
8+
projectId: "noteroom-3ba13",
9+
storageBucket: "noteroom-3ba13.firebasestorage.app",
10+
messagingSenderId: "936732740110",
11+
appId: "1:936732740110:web:eb43c57d566fa140474a5f",
12+
measurementId: "G-4PN6QFN6YX"
13+
};
14+
15+
export default function initializeFirebase() {
16+
const app = initializeApp(firebaseConfig);
17+
isSupported().then((supported) => {
18+
if (supported) getAnalytics(app);
19+
});
20+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ androidxTestExt = "1.3.0"
4040
androidxTest = "1.7.0"
4141
androidxTestOrchestrator = "1.6.1"
4242
firebase = "34.14.1"
43+
firebaseWeb = "12.15.0"
4344
leakCanary = "2.14"
4445
junit = "4.13.2"
4546
mockito = "5.23.0"

0 commit comments

Comments
 (0)