Moves to Google Log in

This commit is contained in:
Julien Lengrand-Lambert
2022-03-30 22:23:49 +02:00
parent e2d46c1543
commit 96504fd737
3 changed files with 20 additions and 62 deletions

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -14,23 +14,16 @@ data class FirebaseUser(
val email: String,
val uid: String,
val accessToken: String,
val lastLogin: Long,
val createdAt: Long
)
@JsModule("@jlengrand/firebase-ports")
@JsNonModule
external object FirebasePorts{
fun signUp(email: String, password: String) : Promise<FirebaseUser>
fun logIn(email: String, password: String) : Promise<FirebaseUser>
fun logIn() : Promise<FirebaseUser>
fun logOut()
}
fun main() {
var email by mutableStateOf("")
var password by mutableStateOf("")
var user : FirebaseUser? by mutableStateOf(null)
renderComposable(rootElementId = "root") {
@@ -44,30 +37,10 @@ fun main() {
if(user == null) {
Div({ style { padding(25.px) } }) {
TextArea(value = email,
attrs = {
onInput { email = it.value }
})
TextArea(value = password,
attrs = {
onInput { password = it.value }
})
Button(attrs = {
onClick {
GlobalScope.launch {
user = FirebasePorts.signUp(email, password).await()
}
}
}) {
Text("Sign Up!")
}
Button(attrs = {
onClick {
GlobalScope.launch {
user = FirebasePorts.logIn(email, password).await()
user = FirebasePorts.logIn().await()
}
}
}) {
@@ -86,15 +59,15 @@ fun main() {
Text("LogOut!")
}
}
}
Div({ style { padding(25.px) } }){
P(){
Text("---------------")
}
Div({ style { padding(25.px) } }){
P(){
Text("---------------")
}
P(){
Text(JSON.stringify(user))
P(){
Text(JSON.stringify(user))
}
}
}
}

View File

@@ -1,43 +1,22 @@
import {FIREBASE_CONFIG} from "./constants";
import { initializeApp } from "firebase/app";
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut } from "firebase/auth";
import { getAuth, signInWithPopup, GoogleAuthProvider, signOut } from "firebase/auth";
const firebaseApp = initializeApp(FIREBASE_CONFIG);
const provider = new GoogleAuthProvider();
const auth = getAuth();
export async function signUp(email, password){
export async function logIn(){
console.log("Signing Up");
console.log("Logging in!");
try {
const userCred = await createUserWithEmailAndPassword(auth, email, password);
const userCred = await signInWithPopup(auth, provider);
return {
accessToken: userCred.user.accessToken,
email: userCred.user.email,
uid: userCred.user.uid,
lastLogin: userCred.user.metadata.lastLoginAt,
createdAt : userCred.user.metadata.createdAt
}
}
catch (e) {
console.log(e);
}
}
export async function logIn(email, password){
console.log("Signing In");
try {
const userCred = await signInWithEmailAndPassword(auth, email, password);
return {
accessToken: userCred.user.accessToken,
email: userCred.user.email,
uid: userCred.user.uid,
lastLogin: userCred.user.metadata.lastLoginAt,
createdAt : userCred.user.metadata.createdAt
}
}
catch (e) {