Starts showing errors

This commit is contained in:
Julien Lengrand-Lambert
2022-03-30 22:53:05 +02:00
parent 96504fd737
commit 7ea6f2edcb
2 changed files with 22 additions and 25 deletions

View File

@@ -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!!)
}
}
}
}
}

View File

@@ -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);
}