diff --git a/client/src/SignalFirebase.ts b/client/src/SignalFirebase.ts index 60791d4..72e378c 100644 --- a/client/src/SignalFirebase.ts +++ b/client/src/SignalFirebase.ts @@ -3,7 +3,7 @@ import { getDatabase, onValue, ref, set, remove } from "firebase/database"; import { v4 as uuid } from "uuid"; import { Answer } from "./RTCTransport"; -import { getAuth, signInWithEmailAndPassword } from "firebase/auth"; +import { browserLocalPersistence, getAuth, setPersistence, signInWithEmailAndPassword } from "firebase/auth"; export async function signalSwarm(offer: string): Promise { @@ -40,13 +40,16 @@ export async function signalSwarm(offer: string): Promise { }); } -export async function signalAccount(offer: string, email: string, password: string): Promise { +export async function signalAccount(offer: string): Promise { let auth = getAuth(); - let creds = await signInWithEmailAndPassword(auth, email, password); + + if (!auth.currentUser) + throw new Error("not signed in"); + const db = getDatabase(); - let peer = ref(db, `/peers/${creds.user.uid}`); + let peer = ref(db, `/peers/${auth.currentUser!.uid}`); diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 0938420..b276da2 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -13,8 +13,6 @@ CircularProgressIndeterminate, Dialog, RadioAnim3, - SegmentedButtonContainer, - SegmentedButtonItem, StyleFromScheme, TextField, } from "m3-svelte"; @@ -30,6 +28,12 @@ import { initializeApp } from "firebase/app"; import TrackerList from "tracker-list"; + import { + browserLocalPersistence, + getAuth, + setPersistence, + signInWithEmailAndPassword, + } from "firebase/auth"; enum ReadyState { Idle, @@ -43,8 +47,8 @@ let rtctransport: RTCTransport | undefined; - let email = "test@test.com"; - let password = "123456"; + let email = ""; + let password = ""; let connectionState = ""; @@ -98,17 +102,12 @@ } async function connectAccount() { - await initFirebase(); rtctransport = transport = createRTCTransport(); state = ReadyState.Connecting; let offer = await rtctransport.createOffer(); connectionState = "Finding your node..."; - let answer = await SignalFirebase.signalAccount( - JSON.stringify(offer), - email, - password - ); + let answer = await SignalFirebase.signalAccount(JSON.stringify(offer)); connectionState = "Linking to node..."; await new Promise((r) => { setTimeout(r, 1000); @@ -280,8 +279,20 @@ - { + await initFirebase(); + + let auth = getAuth(); + await setPersistence(auth, browserLocalPersistence); + + if (!auth.currentUser) { + showLogin = true; + } else { + await connectAccount(); + } + }}>Connect with login {/if} @@ -319,7 +330,13 @@ - +