:wave: Hey folks! Has anyone here implemented Goo...
# kobweb
k
👋 Hey folks! Has anyone here implemented Google (or any social) login in Kobweb? I'm working on adding a "Sign in with Google" button using Firebase Auth on the kobweb frontend, and then passing the token to a Ktor backend for verification. Would really appreciate any GitHub examples or documentation links 🙏 (Vibe coding isn't cutting it this time 😅)
f
That shouldn't be anything Kobweb specific. You are basically asking, "How does Firebase Auth work in Kotlin/JS?" This tutorial should cover it. And for BE, you have to use Firebase Admin tools to verify the resulting JWT token
k
Thanks for the link! I’ve already looked through similar Kotlin/JS references. My main question is about how to organize Firebase-related code in a fullstack Kobweb project. For example, I cloned the fullstack chat example from Kobweb and added
Copy code
kotlin
Copy code
implementation(npm("firebase", "11.6.0"))
inside the
jsMain
block of
site/build.gradle.kts
. But even after that, I’m still unable to access Firebase classes from my Kotlin code. Any example repo on how this is typically set up would be helpful? (Me being a back-end developer)
f
> I’m still unable to access Firebase classes from my Kotlin code That's because it's JS library. Not Kotlin library. You have to create your own bindings or use some library with bindings like firebase-kotlin-sdk. I used to use firebase-kotlin-bindings from @David Herman but I recently migrated to the KMP library.
👍 1
My main question is about how to organize Firebase-related code in a fullstack Kobweb project
Personally, I don't really want to give advice on architecture of your app. I don't have that figured out myself. I just have some sort of
FirebaseSource
implementation on all platforms and I call that pretty much directly from presentation layer (with one "use-case layer" between).
👍 1
a
There is a JVM library which you can use from the server side to validate the token you get from the frontend:
Copy code
[versions]
# For latest version: <https://mvnrepository.com/artifact/com.google.api-client/google-api-client>
google-api-client = "2.7.2"

[libraries]
# <https://developers.google.com/api-client-library/java/google-api-java-client/setup#google-api-client>
google-api-client = { module = "com.google.api-client:google-api-client", version.ref = "google-api-client" }
Refer to the official example. Here is an example usage:
Copy code
private val googleIdTokenVerifier =
        GoogleIdTokenVerifier.Builder(NetHttpTransport(), GsonFactory())
            .setAudience(
                listOf(
// For multiple apps                   googleAndroidClientId,                    googleIosClientId
                )
            )
            .build()

// Null if the id token is invalid
val idToken: GoogleIdToken? = googleIdTokenVerifier.verify(googleIdToken)
f
OP mentioned they are using Firebase auth so the Firebase-Admin JVM sdk should probably be used on the BE. If they are using JVM on BE...
👍 1
k
Thank you for all the responses. The back-end is fine, and I have the options to validate the token and send a JSON based on the result. My only grey area is the frontend in Kobweb. I am going to try this library-> https://gitliveapp.github.io/firebase-kotlin-sdk/
👌 1
d
Yeah, the gitliveapp library is probably the way to go. Good luck!
👍 1