From 7ea6f2edcbcd04340f3348c023e18ad0627ff390 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Wed, 30 Mar 2022 22:53:05 +0200 Subject: [PATCH] Starts showing errors --- src/jsMain/kotlin/Main.kt | 23 +++++++++++++------ src/jsMain/resources/firebase-ports/index.js | 24 +++++--------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/jsMain/kotlin/Main.kt b/src/jsMain/kotlin/Main.kt index 0b14b02..25d113b 100644 --- a/src/jsMain/kotlin/Main.kt +++ b/src/jsMain/kotlin/Main.kt @@ -1,15 +1,11 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.setValue -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.await -import kotlinx.coroutines.launch import org.jetbrains.compose.web.css.* import org.jetbrains.compose.web.dom.* import org.jetbrains.compose.web.renderComposable import kotlin.js.Promise - data class FirebaseUser( val email: String, val uid: String, @@ -25,6 +21,7 @@ external object FirebasePorts{ fun main() { var user : FirebaseUser? by mutableStateOf(null) + var error : String? by mutableStateOf(null) renderComposable(rootElementId = "root") { @@ -39,9 +36,10 @@ fun main() { Button(attrs = { onClick { - GlobalScope.launch { - user = FirebasePorts.logIn().await() - } + error = null + FirebasePorts.logIn() + .then { user = it } + .catch { error = it.message } } }) { Text("LogIn!") @@ -52,6 +50,8 @@ fun main() { Div({ style { padding(25.px) } }) { Button(attrs = { onClick { + error = null + FirebasePorts.logOut() user = null } @@ -70,6 +70,15 @@ fun main() { } } } + + if (error != null) { + Div({ style { padding(25.px) } }){ + P() { + Text("Error: ") + Text(error!!) + } + } + } } } diff --git a/src/jsMain/resources/firebase-ports/index.js b/src/jsMain/resources/firebase-ports/index.js index 709c095..5ae91a9 100644 --- a/src/jsMain/resources/firebase-ports/index.js +++ b/src/jsMain/resources/firebase-ports/index.js @@ -10,28 +10,16 @@ export async function logIn(){ console.log("Logging in!"); - try { - const userCred = await signInWithPopup(auth, provider); + const userCred = await signInWithPopup(auth, provider); - return { - accessToken: userCred.user.accessToken, - email: userCred.user.email, - uid: userCred.user.uid, - } - } - catch (e) { - console.log(e); + return { + accessToken: userCred.user.accessToken, + email: userCred.user.email, + uid: userCred.user.uid, } } export async function logOut(){ - console.log("Logging out!"); - - try { - await signOut(auth); - } - catch (e) { - console.log(e); - } + await signOut(auth); } \ No newline at end of file