Published
Edited
Mar 28, 2022
Importers
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
collection_listen = listen(firebase.firestore().collection("services/testing/example"), {
includeRef: true
})
Insert cell
doc_listen = listen(firebase.firestore().doc("services/testing/example/example1"))
Insert cell
default_value = listen(firebase.firestore().doc("services/testing/example/empty"), {
defaultValue: {}
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
token = JSON.stringify(await user.getIdTokenResult(), null, 2)
Insert cell
viewof user = {
// Protection against click jacking
const url = html`<a href>`.href;
if (
!url.startsWith("https://observablehq.com") &&
!url.startsWith("https://next.observablehq.com")
) {
throw new Error("Login form is not allowed to be embedded");
}

const authContainerId = `firebaseui-auth-container-${Math.random()
.toString(36)
.substring(7)}`;
const form = html`
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/4.6.1/firebase-ui-auth.css" />
<div id="${authContainerId}"></div>
`;
let delayInitialValue = new Promise(async (resolveInitialValue) => {
// Options that are fixed to make it work with Observable
firebaseConfig.uiConfig = firebaseConfig.uiConfig || {};
firebaseConfig.uiConfig.signInFlow = "popup";
firebaseConfig.uiConfig.callbacks = {
signInSuccessWithAuthResult: (authResult, redirectUrl) => false
};
let firstTime = true;
firebase.auth().onAuthStateChanged(function (user) {
if (user != null || !firstTime) {
firstTime = false;
form.value = user;
resolveInitialValue(user);
form.dispatchEvent(new CustomEvent("input"));
}
});
// Initialize the FirebaseUI Widget using Firebase after the div is visible
function pollForUIContainer() {
window.firebase = window._firebase;
if (!document.getElementById(authContainerId)) {
// console.log(`cant find ${authContainerId}`)
setTimeout(pollForUIContainer, 50);
} else {
console.log(`starting for ${authContainerId}`);
const ui =
firebaseui.auth.AuthUI.getInstance() ||
new firebaseui.auth.AuthUI(firebase.auth());
ui.start(`#${authContainerId}`, firebaseConfig.uiConfig);
}
}
pollForUIContainer();
});
form.value = delayInitialValue;
return form;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof testView = new DocsView(firebase.firestore().collection("services/testing/example"))
Insert cell
testView
Insert cell
docsViewTests.test("First value is the result", () => {
// Well this is a pass but the Runtime won't allow a cell to catch the Runtime error
console.log("expect?");
expect(testView[0].string).toBe("aString");
})
Insert cell
Insert cell
docsViewTests.test("Permission errors bubble up", async (done) => {
// Well this is a pass but the Runtime won't allow a cell to catch the Runtime error
try {
await viewof permissionDeniedView.value;
} catch (err) {
done();
}
})
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more