mirror of
https://github.com/jlengrand/kotlin-ports-demo.git
synced 2026-03-10 08:31:20 +00:00
Starts showing errors
This commit is contained in:
@@ -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!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user