Skip to content

Commit dc8dcdd

Browse files
authored
Add snippets for custom dependencies doc (#243)
* Snippets for custom dependencies doc * Add app dependency
1 parent 50d5bdc commit dc8dcdd

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

auth-next/custom-dependencies.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// [SNIPPET_REGISTRY disabled]
2+
// [SNIPPETS_SEPARATION enabled]
3+
4+
// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/custom-dependencies.md
5+
6+
function getAuthEquivalent() {
7+
// [START auth_get_auth_equivalent]
8+
const {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, browserSessionPersistence, indexedDBLocalPersistence} = require("firebase/auth");
9+
const {initializeApp} = require("firebase/app");
10+
11+
const app = initializeApp({/** Your app config */});
12+
const auth = initializeAuth(app, {
13+
persistence: [indexedDBLocalPersistence, browserLocalPersistence, browserSessionPersistence],
14+
popupRedirectResolver: browserPopupRedirectResolver,
15+
});
16+
// [END auth_get_auth_equivalent]
17+
}
18+
19+
function onlyBrowserLocal() {
20+
// [START auth_only_browser_local]
21+
const {initializeAuth, browserLocalPersistence} = require("firebase/auth");
22+
const {initializeApp} = require("firebase/app");
23+
24+
const app = initializeApp({/** Your app config */});
25+
const auth = initializeAuth(app, {
26+
persistence: browserLocalPersistence,
27+
// No popupRedirectResolver defined
28+
});
29+
// [END auth_only_browser_local]
30+
}
31+
32+
function onlyIndexedDB() {
33+
// [START auth_only_indexed_db]
34+
const {initializeAuth, indexedDBLocalPersistence} = require("firebase/auth");
35+
const {initializeApp} = require("firebase/app");
36+
37+
const app = initializeApp({/** Your app config */});
38+
const auth = initializeAuth(app, {
39+
persistence: indexedDBLocalPersistence,
40+
// No popupRedirectResolver defined
41+
});
42+
// [END auth_only_indexed_db]
43+
}
44+
45+
function signInRedirectManualDeps() {
46+
// [START auth_sign_in_redirect_manual_deps]
47+
const {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, indexedDBLocalPersistence, signInWithRedirect, GoogleAuthProvider} = require("firebase/auth");
48+
const {initializeApp} = require("firebase/app");
49+
50+
const app = initializeApp({/** Your app config */});
51+
const auth = initializeAuth(app, {
52+
persistence: [indexedDBLocalPersistence, browserLocalPersistence],
53+
});
54+
55+
// Later
56+
signInWithRedirect(auth, new GoogleAuthProvider(), browserPopupRedirectResolver);
57+
// [END auth_sign_in_redirect_manual_deps]
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./auth-next/custom-dependencies.js
3+
//
4+
// To update the snippets in this file, edit the source and then run
5+
// 'npm run snippets'.
6+
7+
// [START auth_get_auth_equivalent_modular]
8+
import {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, browserSessionPersistence, indexedDBLocalPersistence} from "firebase/auth";
9+
import {initializeApp} from "firebase/app";
10+
11+
const app = initializeApp({/** Your app config */});
12+
const auth = initializeAuth(app, {
13+
persistence: [indexedDBLocalPersistence, browserLocalPersistence, browserSessionPersistence],
14+
popupRedirectResolver: browserPopupRedirectResolver,
15+
});
16+
// [END auth_get_auth_equivalent_modular]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./auth-next/custom-dependencies.js
3+
//
4+
// To update the snippets in this file, edit the source and then run
5+
// 'npm run snippets'.
6+
7+
// [START auth_only_browser_local_modular]
8+
import {initializeAuth, browserLocalPersistence} from "firebase/auth";
9+
import {initializeApp} from "firebase/app";
10+
11+
const app = initializeApp({/** Your app config */});
12+
const auth = initializeAuth(app, {
13+
persistence: browserLocalPersistence,
14+
// No popupRedirectResolver defined
15+
});
16+
// [END auth_only_browser_local_modular]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./auth-next/custom-dependencies.js
3+
//
4+
// To update the snippets in this file, edit the source and then run
5+
// 'npm run snippets'.
6+
7+
// [START auth_only_indexed_db_modular]
8+
import {initializeAuth, indexedDBLocalPersistence} from "firebase/auth";
9+
import {initializeApp} from "firebase/app";
10+
11+
const app = initializeApp({/** Your app config */});
12+
const auth = initializeAuth(app, {
13+
persistence: indexedDBLocalPersistence,
14+
// No popupRedirectResolver defined
15+
});
16+
// [END auth_only_indexed_db_modular]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./auth-next/custom-dependencies.js
3+
//
4+
// To update the snippets in this file, edit the source and then run
5+
// 'npm run snippets'.
6+
7+
// [START auth_sign_in_redirect_manual_deps_modular]
8+
import {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, indexedDBLocalPersistence, signInWithRedirect, GoogleAuthProvider} from "firebase/auth";
9+
import {initializeApp} from "firebase/app";
10+
11+
const app = initializeApp({/** Your app config */});
12+
const auth = initializeAuth(app, {
13+
persistence: [indexedDBLocalPersistence, browserLocalPersistence],
14+
});
15+
16+
// Later
17+
signInWithRedirect(auth, new GoogleAuthProvider(), browserPopupRedirectResolver);
18+
// [END auth_sign_in_redirect_manual_deps_modular]

0 commit comments

Comments
 (0)