Skip to content

Add snippets for custom dependencies doc #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions auth-next/custom-dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// [SNIPPET_REGISTRY disabled]
// [SNIPPETS_SEPARATION enabled]

// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/custom-dependencies.md

function getAuthEquivalent() {
// [START auth_get_auth_equivalent]
const {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, browserSessionPersistence, indexedDBLocalPersistence} = require("firebase/auth");
const {initializeApp} = require("firebase/app");

const app = initializeApp({/** Your app config */});
const auth = initializeAuth(app, {
persistence: [indexedDBLocalPersistence, browserLocalPersistence, browserSessionPersistence],
popupRedirectResolver: browserPopupRedirectResolver,
});
// [END auth_get_auth_equivalent]
}

function onlyBrowserLocal() {
// [START auth_only_browser_local]
const {initializeAuth, browserLocalPersistence} = require("firebase/auth");
const {initializeApp} = require("firebase/app");

const app = initializeApp({/** Your app config */});
const auth = initializeAuth(app, {
persistence: browserLocalPersistence,
// No popupRedirectResolver defined
});
// [END auth_only_browser_local]
}

function onlyIndexedDB() {
// [START auth_only_indexed_db]
const {initializeAuth, indexedDBLocalPersistence} = require("firebase/auth");
const {initializeApp} = require("firebase/app");

const app = initializeApp({/** Your app config */});
const auth = initializeAuth(app, {
persistence: indexedDBLocalPersistence,
// No popupRedirectResolver defined
});
// [END auth_only_indexed_db]
}

function signInRedirectManualDeps() {
// [START auth_sign_in_redirect_manual_deps]
const {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, indexedDBLocalPersistence, signInWithRedirect, GoogleAuthProvider} = require("firebase/auth");
const {initializeApp} = require("firebase/app");

const app = initializeApp({/** Your app config */});
const auth = initializeAuth(app, {
persistence: [indexedDBLocalPersistence, browserLocalPersistence],
});

// Later
signInWithRedirect(auth, new GoogleAuthProvider(), browserPopupRedirectResolver);
// [END auth_sign_in_redirect_manual_deps]
}
16 changes: 16 additions & 0 deletions snippets/auth-next/custom-dependencies/auth_get_auth_equivalent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This snippet file was generated by processing the source file:
// ./auth-next/custom-dependencies.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.

// [START auth_get_auth_equivalent_modular]
import {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, browserSessionPersistence, indexedDBLocalPersistence} from "firebase/auth";
import {initializeApp} from "firebase/app";

const app = initializeApp({/** Your app config */});
const auth = initializeAuth(app, {
persistence: [indexedDBLocalPersistence, browserLocalPersistence, browserSessionPersistence],
popupRedirectResolver: browserPopupRedirectResolver,
});
// [END auth_get_auth_equivalent_modular]
16 changes: 16 additions & 0 deletions snippets/auth-next/custom-dependencies/auth_only_browser_local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This snippet file was generated by processing the source file:
// ./auth-next/custom-dependencies.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.

// [START auth_only_browser_local_modular]
import {initializeAuth, browserLocalPersistence} from "firebase/auth";
import {initializeApp} from "firebase/app";

const app = initializeApp({/** Your app config */});
const auth = initializeAuth(app, {
persistence: browserLocalPersistence,
// No popupRedirectResolver defined
});
// [END auth_only_browser_local_modular]
16 changes: 16 additions & 0 deletions snippets/auth-next/custom-dependencies/auth_only_indexed_db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This snippet file was generated by processing the source file:
// ./auth-next/custom-dependencies.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.

// [START auth_only_indexed_db_modular]
import {initializeAuth, indexedDBLocalPersistence} from "firebase/auth";
import {initializeApp} from "firebase/app";

const app = initializeApp({/** Your app config */});
const auth = initializeAuth(app, {
persistence: indexedDBLocalPersistence,
// No popupRedirectResolver defined
});
// [END auth_only_indexed_db_modular]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This snippet file was generated by processing the source file:
// ./auth-next/custom-dependencies.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.

// [START auth_sign_in_redirect_manual_deps_modular]
import {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, indexedDBLocalPersistence, signInWithRedirect, GoogleAuthProvider} from "firebase/auth";
import {initializeApp} from "firebase/app";

const app = initializeApp({/** Your app config */});
const auth = initializeAuth(app, {
persistence: [indexedDBLocalPersistence, browserLocalPersistence],
});

// Later
signInWithRedirect(auth, new GoogleAuthProvider(), browserPopupRedirectResolver);
// [END auth_sign_in_redirect_manual_deps_modular]