v1.7.3/firefox support uid

This commit is contained in:
2020-09-09 23:04:37 -04:00
parent 29f92783ae
commit c39e25d3ef
2 changed files with 18 additions and 9 deletions
+14 -6
View File
@@ -35,6 +35,19 @@ firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL);
const isAuthed = () => true && firebase.auth().currentUser;
const doAuth = () => firebase.auth().signInAnonymously();
let currentUser;
if (!isAuthed()) doAuth();
else currentUser = firebase.auth().currentUser;
firebase.auth().onAuthStateChanged((user) => {
if (user) {
currentUser = user;
} else {
currentUser = {};
}
});
const fetcher = async (request, sendResponse) => {
if (!isAuthed()) await doAuth();
const { url, method } = request;
@@ -69,11 +82,6 @@ const fetcher = async (request, sendResponse) => {
);
};
const sendAuth = async (sendResponse) => {
if (!isAuthed()) await doAuth();
sendResponse(firebase.auth().currentUser);
};
CHROME_OR_BROWSER.runtime.onInstalled.addListener((details) => {
if (details.reason) {
if (details.reason === 'install') {
@@ -119,7 +127,7 @@ CHROME_OR_BROWSER.runtime.onMessage.addListener((request, sender, sendResponse)
fetcher(request, sendResponse);
break;
case 'GET_AUTH':
sendAuth(sendResponse);
sendResponse({ uid: currentUser.uid });
break;
case 'GET_PARTIES':
sendResponse(