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 isAuthed = () => true && firebase.auth().currentUser;
const doAuth = () => firebase.auth().signInAnonymously(); 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) => { const fetcher = async (request, sendResponse) => {
if (!isAuthed()) await doAuth(); if (!isAuthed()) await doAuth();
const { url, method } = request; 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) => { CHROME_OR_BROWSER.runtime.onInstalled.addListener((details) => {
if (details.reason) { if (details.reason) {
if (details.reason === 'install') { if (details.reason === 'install') {
@@ -119,7 +127,7 @@ CHROME_OR_BROWSER.runtime.onMessage.addListener((request, sender, sendResponse)
fetcher(request, sendResponse); fetcher(request, sendResponse);
break; break;
case 'GET_AUTH': case 'GET_AUTH':
sendAuth(sendResponse); sendResponse({ uid: currentUser.uid });
break; break;
case 'GET_PARTIES': case 'GET_PARTIES':
sendResponse( sendResponse(
+4 -3
View File
@@ -127,8 +127,8 @@ export const scrollThread = () => {
}, 250); }, 250);
}; };
export const getUserUid = async () => export const getUserUid = async () => {
new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
CHROME_OR_BROWSER.runtime.sendMessage( CHROME_OR_BROWSER.runtime.sendMessage(
{ {
type: 'GET_AUTH', type: 'GET_AUTH',
@@ -136,10 +136,11 @@ export const getUserUid = async () =>
(response) => { (response) => {
const { uid } = response; const { uid } = response;
updateLocalData({ userUid: uid }); updateLocalData({ userUid: uid });
resolve(uid); resolve(response);
} }
); );
}); });
};
export const fetcher = async ({ endpoint, method, ...args }) => { export const fetcher = async ({ endpoint, method, ...args }) => {
const url = `${API_HOST}/${endpoint}`; const url = `${API_HOST}/${endpoint}`;