├── functions-next
├── .gitignore
└── package.json
├── firestore
├── .gitignore
├── firebase.json
├── firestore.rules
├── emulator-suite.js
├── package.json
└── index.html
├── .gitignore
├── placeholder.js
├── scripts
├── package.json
└── checkdirty.sh
├── auth
├── initialization.txt
├── package.json
├── anonymous.js
├── emulator-suite.js
└── custom.js
├── perf
└── package.json
├── analytics
└── package.json
├── appcheck
└── package.json
├── auth-next
├── package.json
├── anonymous.js
├── custom.js
└── emulator-suite.js
├── database
├── package.json
├── index.js
├── emulator-suite.js
└── sharding.js
├── functions
├── package.json
└── emulator-suite.js
├── messaging
└── package.json
├── perf-next
└── package.json
├── storage
├── package.json
├── delete-files.js
└── emulator-suite.js
├── firebaseapp
└── package.json
├── installations
└── package.json
├── analytics-next
└── package.json
├── appcheck-next
└── package.json
├── database-next
├── package.json
├── index.js
└── emulator-suite.js
├── messaging-next
└── package.json
├── remoteconfig
└── package.json
├── storage-next
├── package.json
├── emulator-suite.js
└── delete-files.js
├── firebaseapp-next
└── package.json
├── remoteconfig-next
└── package.json
├── eslint.config.js
├── snippets
├── placeholder
│ └── coming_soon.js
├── perf-next
│ └── index
│ │ ├── perf_import.js
│ │ ├── perf_import_app.js
│ │ ├── perf_get_instance.js
│ │ ├── perf_singleton.js
│ │ ├── perf_add_custom_trace.js
│ │ ├── perf_initialize_app.js
│ │ ├── perf_user_timing_marks.js
│ │ ├── perf_add_custom_attributes.js
│ │ └── perf_add_custom_metrics.js
├── auth-next
│ ├── github
│ │ ├── auth_github_provider_scopes.js
│ │ ├── auth_github_provider_params.js
│ │ ├── auth_github_provider_create.js
│ │ └── auth_github_provider_credential.js
│ ├── facebook
│ │ ├── auth_facebook_provider_scopes.js
│ │ ├── auth_facebook_provider_params.js
│ │ ├── auth_facebook_provider_create.js
│ │ ├── auth_facebook_provider_credential.js
│ │ └── auth_facebook_checksameuser.js
│ ├── apple
│ │ ├── auth_apple_provider_scopes.js
│ │ ├── auth_apple_provider_create.js
│ │ ├── auth_apple_provider_params.js
│ │ └── auth_apple_signin_redirect.js
│ ├── phone-auth
│ │ ├── auth_get_recaptcha_response.js
│ │ ├── auth_phone_recaptcha_render.js
│ │ ├── auth_phone_recaptcha_verifier_simple.js
│ │ ├── auth_phone_verify_code.js
│ │ ├── auth_phone_recaptcha_verifier_invisible.js
│ │ └── auth_phone_recaptcha_verifier_visible.js
│ ├── twitter
│ │ ├── auth_twitter_provider_params.js
│ │ ├── auth_twitter_provider_create.js
│ │ └── auth_twitter_provider_credential.js
│ ├── google-signin
│ │ ├── auth_google_provider_scopes.js
│ │ ├── auth_google_provider_params.js
│ │ ├── auth_google_provider_create.js
│ │ ├── auth_google_provider_credential.js
│ │ ├── auth_google_signin_credential.js
│ │ └── auth_google_checksameuser.js
│ ├── microsoft-oauth
│ │ ├── auth_msft_provider_scopes.js
│ │ ├── auth_msft_create_provider.js
│ │ ├── auth_msft_signin_redirect.js
│ │ ├── auth_msft_provider_params.js
│ │ ├── auth_msft_provider_params_tenant.js
│ │ ├── auth_msft_signin_popup.js
│ │ └── auth_msft_signin_redirect_result.js
│ ├── oidc
│ │ ├── auth_oidc_provider_create.js
│ │ └── auth_oidc_signin_redirect.js
│ ├── saml
│ │ ├── auth_saml_provider_create.js
│ │ └── auth_saml_signin_redirect.js
│ ├── cordova
│ │ └── auth_create_google_provider.js
│ ├── index
│ │ ├── auth_signin_redirect.js
│ │ ├── auth_make_email_credential.js
│ │ ├── auth_make_google_credential.js
│ │ ├── auth_make_facebook_credential.js
│ │ ├── auth_sign_out.js
│ │ ├── auth_set_language_code.js
│ │ ├── auth_current_user.js
│ │ ├── auth_init_custom_domain.js
│ │ ├── auth_state_listener.js
│ │ └── auth_signin_credential.js
│ ├── yahoo-oauth
│ │ ├── auth_yahoo_provider_create.js
│ │ ├── auth_yahoo_signin_redirect.js
│ │ ├── auth_yahoo_provider_params.js
│ │ ├── auth_yahoo_provider_scopes.js
│ │ └── auth_yahoo_signin_popup.js
│ ├── service-worker-sessions
│ │ ├── auth_svc_listen_activate.js
│ │ ├── auth_svc_register.js
│ │ ├── auth_svc_get_idtoken.js
│ │ └── auth_svc_sign_in_email.js
│ ├── multi-tenancy
│ │ ├── multitenant_set_tenant.js
│ │ ├── multitenant_switch_tenant.js
│ │ ├── multitenant_signin_custom_token.js
│ │ ├── multitenant_signin_password.js
│ │ ├── multitenant_signup_password.js
│ │ ├── multitenant_create_custom_token.js
│ │ ├── multitenant_switch_tenant_multiinstance.js
│ │ ├── multitenant_send_emaillink.js
│ │ └── multitenant_signin_saml_popup.js
│ ├── emulator-suite
│ │ ├── auth_emulator_connect.js
│ │ └── auth_emulator_google_credential.js
│ ├── link-multiple-accounts
│ │ ├── auth_make_email_credential.js
│ │ ├── auth_link_with_redirect.js
│ │ ├── auth_unlink_provider.js
│ │ ├── auth_get_providers.js
│ │ ├── auth_simple_link.js
│ │ ├── auth_anonymous_link.js
│ │ ├── auth_get_redirect_result.js
│ │ └── auth_link_with_popup.js
│ ├── email
│ │ ├── auth_send_email_verification.js
│ │ ├── auth_send_password_reset.js
│ │ ├── auth_signin_password.js
│ │ └── auth_signup_password.js
│ ├── manage
│ │ ├── auth_delete_user.js
│ │ ├── auth_update_user_email.js
│ │ ├── send_email_verification.js
│ │ ├── auth_send_password_reset.js
│ │ ├── auth_update_password.js
│ │ ├── auth_update_user_profile.js
│ │ ├── auth_reauth_with_credential.js
│ │ ├── auth_get_user_profile_provider.js
│ │ └── auth_get_user_profile.js
│ ├── anonymous
│ │ └── auth_anon_sign_in.js
│ ├── custom-dependencies
│ │ ├── auth_only_indexed_db.js
│ │ ├── auth_only_browser_local.js
│ │ ├── auth_get_auth_equivalent.js
│ │ └── auth_sign_in_redirect_manual_deps.js
│ ├── custom
│ │ └── auth_sign_in_custom.js
│ └── email-link-auth
│ │ └── auth_email_link_send.js
├── firestore-next
│ ├── test-firestore
│ │ ├── one_disjunction.js
│ │ ├── two_disjunctions.js
│ │ ├── simple_query_not_equal.js
│ │ ├── delete_document.js
│ │ ├── doc_reference.js
│ │ ├── in_filter.js
│ │ ├── cities_document_set.js
│ │ ├── collection_reference.js
│ │ ├── order_and_limit.js
│ │ ├── not_in_filter.js
│ │ ├── order_and_end.js
│ │ ├── doc_reference_alternative.js
│ │ ├── order_multiple.js
│ │ ├── order_and_start.js
│ │ ├── subcollection_reference.js
│ │ ├── order_and_limit_desc.js
│ │ ├── array_contains_filter.js
│ │ ├── set_with_merge.js
│ │ ├── in_filter_with_array.js
│ │ ├── invalid_range_filters.js
│ │ ├── count_aggregate_collection.js
│ │ ├── filter_and_order.js
│ │ ├── or_query.js
│ │ ├── invalid_filter_and_order.js
│ │ ├── valid_filter_and_order.js
│ │ ├── four_disjunctions_compact.js
│ │ ├── fs_setup_cache.js
│ │ ├── listen_document.js
│ │ ├── enable_network.js
│ │ ├── simple_queries_again.js
│ │ ├── array_contains_any_filter.js
│ │ ├── count_aggregate_query.js
│ │ ├── get_all_users.js
│ │ ├── new_document.js
│ │ ├── set_document.js
│ │ ├── example_filters.js
│ │ ├── listen_with_metadata.js
│ │ ├── set_custom_object.js
│ │ ├── update_document.js
│ │ ├── chain_filters.js
│ │ ├── disable_network.js
│ │ ├── handle_listen_errors.js
│ │ ├── valid_range_filters.js
│ │ ├── update_delete_field.js
│ │ ├── detach_listener.js
│ │ ├── add_document.js
│ │ ├── listen_document_local.js
│ │ ├── simple_queries.js
│ │ ├── four_disjunctions.js
│ │ ├── get_multiple_all.js
│ │ ├── update_document_increment.js
│ │ ├── update_with_server_timestamp.js
│ │ ├── get_document.js
│ │ ├── start_doc.js
│ │ ├── fs_collection_group_query.js
│ │ ├── get_multiple.js
│ │ ├── add_ada_lovelace.js
│ │ ├── listen_for_users.js
│ │ ├── firestore_query_subcollection.js
│ │ ├── get_custom_object.js
│ │ ├── listen_multiple.js
│ │ ├── add_alan_turing.js
│ │ ├── update_document_array.js
│ │ ├── start_multiple_orderby.js
│ │ ├── update_document_nested.js
│ │ ├── data_types.js
│ │ ├── transaction.js
│ │ ├── get_document_options.js
│ │ ├── write_batch.js
│ │ └── use_from_cache.js
│ ├── test-solution-aggregation
│ │ ├── sample_doc.js
│ │ └── get_collection_ratings.js
│ ├── test-solution-arrays
│ │ ├── post_with_array.js
│ │ ├── post_with_map.js
│ │ ├── query_in_category_timestamp.js
│ │ ├── post_with_map_advanced.js
│ │ ├── query_in_category_timestamp_invalid.js
│ │ └── query_in_category.js
│ ├── emulator-suite
│ │ └── fs_emulator_connect.js
│ ├── test-solution-counters
│ │ ├── get_count.js
│ │ ├── increment_counter.js
│ │ └── create_counter.js
│ └── test-solution-geoqueries
│ │ └── fs_geo_add_hash.js
├── database-next
│ ├── index
│ │ └── rtdb_get_reference.js
│ ├── offline
│ │ ├── rtdb_ondisconnect_callback.js
│ │ ├── rtdb_ondisconnect_cancel.js
│ │ ├── rtdb_set_server_timestamp.js
│ │ ├── rtdb_ondisconnect_simple.js
│ │ ├── rtdb_estimate_clock_skew.js
│ │ └── rtdb_detect_connection_state.js
│ ├── lists-of-data
│ │ ├── rtdb_social_recent.js
│ │ ├── rtdb_social_most_viewed.js
│ │ ├── rtdb_social_push.js
│ │ ├── rtdb_social_most_starred.js
│ │ └── rtdb_social_listen_value.js
│ ├── emulator-suite
│ │ ├── rtdb_emulator_flush.js
│ │ └── rtdb_emulator_connect.js
│ ├── read-and-write
│ │ ├── rtdb_write_new_user.js
│ │ ├── rtdb_social_listen_star_count.js
│ │ ├── rtdb_read_once_get.js
│ │ ├── rtdb_social_completion_callback.js
│ │ ├── rtdb_write_new_user_completion.js
│ │ ├── rtdb_social_single_value_read.js
│ │ └── rtdb_social_star_increment.js
│ └── sharding
│ │ └── rtdb_multiple_instances.js
├── remoteconfig-next
│ └── index
│ │ ├── rc_set_default_values.js
│ │ ├── rc_get_instance.js
│ │ ├── rc_get_values.js
│ │ ├── rc_set_minimum_fetch_time.js
│ │ └── rc_fetch_config_callback.js
├── analytics-next
│ ├── index
│ │ ├── analytics_initialize.js
│ │ ├── analytics_log_event.js
│ │ ├── analytics_set_user_properties.js
│ │ ├── analytics_log_event_custom_params.js
│ │ ├── analytics_log_event_params.js
│ │ └── analytics_record_screen_view.js
│ └── ecommerce
│ │ ├── analytics_ecommerce_remove_cart.js
│ │ ├── analytics_ecommerce_view_item_details.js
│ │ ├── analytics_ecommerce_select_item.js
│ │ ├── analytics_ecommerce_checkout.js
│ │ ├── analytics_ecommerce_view_item_list.js
│ │ ├── analytics_ecommerce_payment_info.js
│ │ ├── analytics_ecommerce_shipping_info.js
│ │ └── analytics_ecommerce_purchase.js
├── messaging-next
│ └── index
│ │ ├── messaging_get_messaging_object.js
│ │ ├── messaging_delete_token.js
│ │ ├── messaging_request_permission.js
│ │ └── messaging_receive_message.js
├── storage-next
│ ├── file-metadata
│ │ ├── storage_custom_metadata.js
│ │ ├── storage_get_metadata.js
│ │ └── storage_delete_metadata.js
│ ├── index
│ │ ├── storage_multiple_buckets.js
│ │ ├── storage_custom_app.js
│ │ └── storage_initialize.js
│ ├── create-reference
│ │ ├── storage_create_ref.js
│ │ ├── storage_navigate_ref_chain.js
│ │ ├── storage_create_ref_child.js
│ │ ├── storage_navigate_ref.js
│ │ └── storage_ref_properties.js
│ ├── emulator-suite
│ │ └── storage_emulator_connect.js
│ ├── upload-files
│ │ ├── storage_upload_blob.js
│ │ ├── storage_upload_bytes.js
│ │ ├── storage_upload_metadata.js
│ │ ├── storage_manage_uploads.js
│ │ └── storage_upload_ref.js
│ └── delete-files
│ │ └── storage_delete_file.js
├── firebaseapp-next
│ └── firebaseapp
│ │ ├── firebase_secondary.js
│ │ └── firebase_options.js
├── functions-next
│ ├── emulator-suite
│ │ ├── fb_functions_emulator_connect.js
│ │ └── fb_functions_callable_call.js
│ └── callable
│ │ ├── fb_functions_initialize.js
│ │ └── fb_functions_call_add_message.js
└── appcheck-next
│ └── index
│ └── appcheck_initialize_custom_provider.js
├── firebaseserverapp-next
├── package.json
└── firebaseserverapp.js
├── firestore-next
├── emulator-suite.js
└── package.json
├── package.json
└── SNIPPETS.md
/functions-next/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 |
--------------------------------------------------------------------------------
/firestore/.gitignore:
--------------------------------------------------------------------------------
1 | firebase-debug.log
2 |
--------------------------------------------------------------------------------
/firestore/firebase.json:
--------------------------------------------------------------------------------
1 | {
2 | "hosting": {
3 | "public": "."
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | package-lock.json
2 | node_modules
3 |
4 | tsconfig.json
5 | dist/
6 | .DS_Store
7 | .idea
8 |
--------------------------------------------------------------------------------
/placeholder.js:
--------------------------------------------------------------------------------
1 | // [SNIPPET_REGISTRY disabled]
2 | // [SNIPPETS_SEPARATION enabled]
3 |
4 | // [START coming_soon]
5 | // TODO: Snippet coming soon!
6 | // [END coming_soon]
7 |
--------------------------------------------------------------------------------
/firestore/firestore.rules:
--------------------------------------------------------------------------------
1 |
2 | service cloud.firestore {
3 | match /databases/{database}/documents {
4 | match /{document=**} {
5 | allow read, write;
6 | }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/scripts/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "scripts",
3 | "version": "1.0.0",
4 | "type": "module",
5 | "description": "Internal repo scripts",
6 | "scripts": {
7 | },
8 | "author": "samstern@google.com",
9 | "license": "Apache-2.0"
10 | }
11 |
--------------------------------------------------------------------------------
/auth/initialization.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/perf/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "perf",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/analytics/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "analytics",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/appcheck/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "appcheck",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/auth-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "auth-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/database/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "database",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache 2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/functions/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "functions",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/messaging/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "messaging",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/perf-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "perf-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/storage/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "storage",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/firebaseapp/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "firebaseapp",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/functions/emulator-suite.js:
--------------------------------------------------------------------------------
1 | import firebase from "firebase/app";
2 | import "firebase/functions";
3 |
4 | function emulatorSettings() {
5 | // [START fb_functions_emulator_connect]
6 | firebase.functions().useEmulator("127.0.0.1", 5001);
7 | // [END fb_functions_emulator_connect]
8 | }
9 |
--------------------------------------------------------------------------------
/installations/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "installations",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "echo 'Installations build temporarily disabled'"
6 | },
7 | "license": "Apache 2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/analytics-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "analytics-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/appcheck-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "appcheck-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/database-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "database-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/functions-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "functions-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/messaging-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "messaging-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/remoteconfig/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "remoteconfig",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/storage-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "storage-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/firebaseapp-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "firebaseapp-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/remoteconfig-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "remoteconfig-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/database-next/index.js:
--------------------------------------------------------------------------------
1 | // [SNIPPET_REGISTRY disabled]
2 | // [SNIPPETS_SEPARATION enabled]
3 |
4 | function getReference() {
5 | // [START rtdb_get_reference]
6 | const { getDatabase } = require("firebase/database");
7 |
8 | const database = getDatabase();
9 | // [END rtdb_get_reference]
10 | }
11 |
--------------------------------------------------------------------------------
/eslint.config.js:
--------------------------------------------------------------------------------
1 |
2 | import { defineConfig } from "eslint/config";
3 | import js from "@eslint/js";
4 |
5 | export default defineConfig([
6 | js.configs.recommended,
7 | {
8 | rules: {
9 | "no-unused-vars": "off",
10 | "no-undef": "off",
11 | "no-redeclare": "off"
12 | },
13 | },
14 | ]);
15 |
--------------------------------------------------------------------------------
/snippets/placeholder/coming_soon.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./placeholder.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START coming_soon_modular]
8 | // TODO: Snippet coming soon!
9 | // [END coming_soon_modular]
--------------------------------------------------------------------------------
/firebaseserverapp-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "firebaseserverapp-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^10.0.0",
10 | "next": "^14.1.3"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/auth/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "auth",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache 2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0",
10 | "firebase-admin": "^12.0.0",
11 | "firebaseui": "^5.0.0"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/snippets/perf-next/index/perf_import.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./perf-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START perf_import_modular]
8 | import { getPerformance } from "firebase/performance";
9 | // [END perf_import_modular]
--------------------------------------------------------------------------------
/snippets/perf-next/index/perf_import_app.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./perf-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START perf_import_app_modular]
8 | import { initializeApp } from "firebase/app";
9 | // [END perf_import_app_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/github/auth_github_provider_scopes.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/github.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_github_provider_scopes_modular]
8 | provider.addScope('repo');
9 | // [END auth_github_provider_scopes_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/one_disjunction.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START one_disjunction_modular]
8 | query(collectionRef, where("a", "==", 1));
9 | // [END one_disjunction_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/facebook/auth_facebook_provider_scopes.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/facebook.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // / [START auth_facebook_provider_scopes_modular]
8 | provider.addScope('user_birthday');
9 | // [END auth_facebook_provider_scopes_modular]
--------------------------------------------------------------------------------
/scripts/checkdirty.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 |
4 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5 |
6 | git add .
7 |
8 | if [[ $(git diff --stat HEAD) != '' ]]; then
9 | git diff --stat HEAD
10 | echo
11 | echo 'Error: git diff is dirty ... did you forget to run "npm run snippets" after adding snippets?'
12 | exit 1
13 | else
14 | echo 'Success: git diff is clean'
15 | fi
16 |
--------------------------------------------------------------------------------
/snippets/auth-next/apple/auth_apple_provider_scopes.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/apple.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_apple_provider_scopes_modular]
8 | provider.addScope('email');
9 | provider.addScope('name');
10 | // [END auth_apple_provider_scopes_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/two_disjunctions.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START two_disjunctions_modular]
8 | query(collectionRef, or( where("a", "==", 1), where("b", "==", 2) ));
9 | // [END two_disjunctions_modular]
--------------------------------------------------------------------------------
/firestore/emulator-suite.js:
--------------------------------------------------------------------------------
1 | import firebase from "firebase/app";
2 | import 'firebase/firestore';
3 |
4 | function onDocumentReady() {
5 | // [START fs_emulator_connect]
6 | // Firebase previously initialized using firebase.initializeApp().
7 | var db = firebase.firestore();
8 | if (location.hostname === "localhost") {
9 | db.useEmulator("127.0.0.1", 8080);
10 | }
11 | // [END fs_emulator_connect]
12 | }
13 |
--------------------------------------------------------------------------------
/snippets/perf-next/index/perf_get_instance.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./perf-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START perf_get_instance_modular]
8 | import { getPerformance } from "firebase/performance";
9 | const perf = getPerformance();
10 | // [END perf_get_instance_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/phone-auth/auth_get_recaptcha_response.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/phone-auth.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_recaptcha_response_modular]
8 | const recaptchaResponse = grecaptcha.getResponse(recaptchaWidgetId);
9 | // [END auth_get_recaptcha_response_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/twitter/auth_twitter_provider_params.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/twitter.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_twitter_provider_params_modular]
8 | provider.setCustomParameters({
9 | 'lang': 'es'
10 | });
11 | // [END auth_twitter_provider_params_modular]
--------------------------------------------------------------------------------
/database/index.js:
--------------------------------------------------------------------------------
1 | // These samples are intended for Web so this import would normally be
2 | // done in HTML however using modules here is more convenient for
3 | // ensuring sample correctness offline.
4 | import firebase from "firebase/app";
5 | import "firebase/database";
6 |
7 | function getReference() {
8 | // [START rtdb_get_reference]
9 | var database = firebase.database();
10 | // [END rtdb_get_reference]
11 | }
12 |
--------------------------------------------------------------------------------
/snippets/auth-next/github/auth_github_provider_params.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/github.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_github_provider_params_modular]
8 | provider.setCustomParameters({
9 | 'allow_signup': 'false'
10 | });
11 | // [END auth_github_provider_params_modular]
--------------------------------------------------------------------------------
/snippets/database-next/index/rtdb_get_reference.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_get_reference_modular]
8 | import { getDatabase } from "firebase/database";
9 |
10 | const database = getDatabase();
11 | // [END rtdb_get_reference_modular]
--------------------------------------------------------------------------------
/snippets/perf-next/index/perf_singleton.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./perf-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START perf_singleton_modular]
8 | // Initialize Performance Monitoring and get a reference to the service
9 | const perf = getPerformance(app);
10 | // [END perf_singleton_modular]
--------------------------------------------------------------------------------
/snippets/remoteconfig-next/index/rc_set_default_values.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./remoteconfig-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rc_set_default_values_modular]
8 | remoteConfig.defaultConfig = {
9 | "welcome_message": "Welcome"
10 | };
11 | // [END rc_set_default_values_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/facebook/auth_facebook_provider_params.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/facebook.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_facebook_provider_params_modular]
8 | provider.setCustomParameters({
9 | 'display': 'popup'
10 | });
11 | // [END auth_facebook_provider_params_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/google-signin/auth_google_provider_scopes.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/google-signin.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_google_provider_scopes_modular]
8 | provider.addScope('https://www.googleapis.com/auth/contacts.readonly');
9 | // [END auth_google_provider_scopes_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/simple_query_not_equal.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START simple_query_not_equal_modular]
8 | const notCapitalQuery = query(citiesRef, where("capital", "!=", false));
9 | // [END simple_query_not_equal_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/index/analytics_initialize.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_initialize_modular]
8 | import { getAnalytics } from "firebase/analytics";
9 |
10 | const analytics = getAnalytics();
11 | // [END analytics_initialize_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/microsoft-oauth/auth_msft_provider_scopes.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/microsoft-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_msft_provider_scopes_modular]
8 | provider.addScope('mail.read');
9 | provider.addScope('calendars.read');
10 | // [END auth_msft_provider_scopes_modular]
--------------------------------------------------------------------------------
/snippets/remoteconfig-next/index/rc_get_instance.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./remoteconfig-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rc_get_instance_modular]
8 | import { getRemoteConfig } from "firebase/remote-config";
9 |
10 | const remoteConfig = getRemoteConfig();
11 | // [END rc_get_instance_modular]
--------------------------------------------------------------------------------
/snippets/remoteconfig-next/index/rc_get_values.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./remoteconfig-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rc_get_values_modular]
8 | import { getValue } from "firebase/remote-config";
9 |
10 | const val = getValue(remoteConfig, "welcome_messsage");
11 | // [END rc_get_values_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/google-signin/auth_google_provider_params.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/google-signin.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_google_provider_params_modular]
8 | provider.setCustomParameters({
9 | 'login_hint': 'user@example.com'
10 | });
11 | // [END auth_google_provider_params_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/delete_document.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START delete_document_modular]
8 | import { doc, deleteDoc } from "firebase/firestore";
9 |
10 | await deleteDoc(doc(db, "cities", "DC"));
11 | // [END delete_document_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/doc_reference.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START doc_reference_modular]
8 | import { doc } from "firebase/firestore";
9 |
10 | const alovelaceDocumentRef = doc(db, 'users', 'alovelace');
11 | // [END doc_reference_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/apple/auth_apple_provider_create.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/apple.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_apple_provider_create_modular]
8 | import { OAuthProvider } from "firebase/auth";
9 |
10 | const provider = new OAuthProvider('apple.com');
11 | // [END auth_apple_provider_create_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/oidc/auth_oidc_provider_create.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/oidc.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_oidc_provider_create_modular]
8 | import { OAuthProvider } from "firebase/auth";
9 |
10 | const provider = new OAuthProvider("oidc.myProvider");
11 | // [END auth_oidc_provider_create_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-aggregation/sample_doc.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-aggregation.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START sample_doc_modular]
8 | const arinellDoc = {
9 | name: 'Arinell Pizza',
10 | avgRating: 4.65,
11 | numRatings: 683
12 | };
13 | // [END sample_doc_modular]
--------------------------------------------------------------------------------
/firestore-next/emulator-suite.js:
--------------------------------------------------------------------------------
1 | // [SNIPPET_REGISTRY disabled]
2 | // [SNIPPETS_SEPARATION enabled]
3 |
4 | function onDocumentReady() {
5 | // [START fs_emulator_connect]
6 | const { getFirestore, connectFirestoreEmulator } = require("firebase/firestore");
7 |
8 | // firebaseApps previously initialized using initializeApp()
9 | const db = getFirestore();
10 | connectFirestoreEmulator(db, '127.0.0.1', 8080);
11 | // [END fs_emulator_connect]
12 | }
13 |
--------------------------------------------------------------------------------
/snippets/auth-next/github/auth_github_provider_create.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/github.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_github_provider_create_modular]
8 | import { GithubAuthProvider } from "firebase/auth";
9 |
10 | const provider = new GithubAuthProvider();
11 | // [END auth_github_provider_create_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/in_filter.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START in_filter_modular]
8 | import { query, where } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, where('country', 'in', ['USA', 'Japan']));
11 | // [END in_filter_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/phone-auth/auth_phone_recaptcha_render.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/phone-auth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_phone_recaptcha_render_modular]
8 | recaptchaVerifier.render().then((widgetId) => {
9 | window.recaptchaWidgetId = widgetId;
10 | });
11 | // [END auth_phone_recaptcha_render_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/saml/auth_saml_provider_create.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/saml.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_saml_provider_create_modular]
8 | import { SAMLAuthProvider } from "firebase/auth";
9 |
10 | const provider = new SAMLAuthProvider("saml.myProvider");
11 | // [END auth_saml_provider_create_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/twitter/auth_twitter_provider_create.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/twitter.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_twitter_provider_create_modular]
8 | import { TwitterAuthProvider } from "firebase/auth";
9 |
10 | const provider = new TwitterAuthProvider();
11 | // [END auth_twitter_provider_create_modular]
--------------------------------------------------------------------------------
/snippets/messaging-next/index/messaging_get_messaging_object.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./messaging-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START messaging_get_messaging_object_modular]
8 | import { getMessaging } from "firebase/messaging";
9 |
10 | const messaging = getMessaging();
11 | // [END messaging_get_messaging_object_modular]
--------------------------------------------------------------------------------
/firestore/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "firestore",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^8.10.0",
10 | "geofire-common": "^5.1.0"
11 | },
12 | "devDependencies": {
13 | "@types/chai": "^4.2.12",
14 | "@types/mocha": "^8.0.3",
15 | "chai": "^4.2.0",
16 | "mocha": "^8.1.3"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/snippets/auth-next/apple/auth_apple_provider_params.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/apple.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_apple_provider_params_modular]
8 | provider.setCustomParameters({
9 | // Localize the Apple authentication screen in French.
10 | locale: 'fr'
11 | });
12 | // [END auth_apple_provider_params_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/cordova/auth_create_google_provider.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/cordova.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_create_google_provider_modular]
8 | import { GoogleAuthProvider } from "firebase/auth/cordova";
9 |
10 | const provider = new GoogleAuthProvider();
11 | // [END auth_create_google_provider_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/index/auth_signin_redirect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_signin_redirect_modular]
8 | import { getAuth, signInWithRedirect } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithRedirect(auth, provider);
12 | // [END auth_signin_redirect_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_create.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/yahoo-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_yahoo_provider_create_modular]
8 | import { OAuthProvider } from "firebase/auth";
9 |
10 | const provider = new OAuthProvider('yahoo.com');
11 | // [END auth_yahoo_provider_create_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/cities_document_set.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START cities_document_set_modular]
8 | import { doc, setDoc } from "firebase/firestore";
9 |
10 | await setDoc(doc(db, "cities", "new-city-id"), data);
11 | // [END cities_document_set_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/collection_reference.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START collection_reference_modular]
8 | import { collection } from "firebase/firestore";
9 |
10 | const usersCollectionRef = collection(db, 'users');
11 | // [END collection_reference_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/order_and_limit.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START order_and_limit_modular]
8 | import { query, orderBy, limit } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, orderBy("name"), limit(3));
11 | // [END order_and_limit_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/facebook/auth_facebook_provider_create.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/facebook.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_facebook_provider_create_modular]
8 | import { FacebookAuthProvider } from "firebase/auth";
9 |
10 | const provider = new FacebookAuthProvider();
11 | // [END auth_facebook_provider_create_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/google-signin/auth_google_provider_create.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/google-signin.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_google_provider_create_modular]
8 | import { GoogleAuthProvider } from "firebase/auth";
9 |
10 | const provider = new GoogleAuthProvider();
11 | // [END auth_google_provider_create_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/index/auth_make_email_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_make_email_credential_modular]
8 | import { EmailAuthProvider } from "firebase/auth";
9 |
10 | const credential = EmailAuthProvider.credential(email, password);
11 | // [END auth_make_email_credential_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/microsoft-oauth/auth_msft_create_provider.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/microsoft-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_msft_create_provider_modular]
8 | import { OAuthProvider } from "firebase/auth";
9 |
10 | const provider = new OAuthProvider('microsoft.com');
11 | // [END auth_msft_create_provider_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/service-worker-sessions.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_svc_listen_activate_modular]
8 | self.addEventListener('activate', (event) => {
9 | event.waitUntil(clients.claim());
10 | });
11 | // [END auth_svc_listen_activate_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/not_in_filter.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START not_in_filter_modular]
8 | import { query, where } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, where('country', 'not-in', ['USA', 'Japan']));
11 | // [END not_in_filter_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/oidc/auth_oidc_signin_redirect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/oidc.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_oidc_signin_redirect_modular]
8 | import { getAuth, signInWithRedirect } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithRedirect(auth, provider);
12 | // [END auth_oidc_signin_redirect_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/saml/auth_saml_signin_redirect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/saml.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_saml_signin_redirect_modular]
8 | import { getAuth, signInWithRedirect } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithRedirect(auth, provider);
12 | // [END auth_saml_signin_redirect_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/order_and_end.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START order_and_end_modular]
8 | import { query, orderBy, endAt } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, orderBy("population"), endAt(1000000));
11 | // [END order_and_end_modular]
--------------------------------------------------------------------------------
/firestore-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "firestore-next",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6 | },
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "firebase": "^12.4.0",
10 | "geofire-common": "^6.0.0"
11 | },
12 | "devDependencies": {
13 | "@types/chai": "^5.2.3",
14 | "@types/mocha": "^10.0.10",
15 | "chai": "^6.2.0",
16 | "mocha": "^11.7.4"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/snippets/auth-next/apple/auth_apple_signin_redirect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/apple.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_apple_signin_redirect_modular]
8 | import { getAuth, signInWithRedirect } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithRedirect(auth, provider);
12 | // [END auth_apple_signin_redirect_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/github/auth_github_provider_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/github.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_github_provider_credential_modular]
8 | import { GithubAuthProvider } from "firebase/auth";
9 |
10 | const credential = GithubAuthProvider.credential(token);
11 | // [END auth_github_provider_credential_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/doc_reference_alternative.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START doc_reference_alternative_modular]
8 | import { doc } from "firebase/firestore";
9 |
10 | const alovelaceDocumentRef = doc(db, 'users/alovelace');
11 | // [END doc_reference_alternative_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/order_multiple.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START order_multiple_modular]
8 | import { query, orderBy } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, orderBy("state"), orderBy("population", "desc"));
11 | // [END order_multiple_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/multi-tenancy/multitenant_set_tenant.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/multi-tenancy.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START multitenant_set_tenant_modular]
8 | import { getAuth } from "firebase/auth";
9 | const auth = getAuth();
10 | const tenantId = "TENANT_ID1";
11 | auth.tenantId = tenantId;
12 | // [END multitenant_set_tenant_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/order_and_start.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START order_and_start_modular]
8 | import { query, orderBy, startAt } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, orderBy("population"), startAt(1000000));
11 | // [END order_and_start_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/subcollection_reference.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START subcollection_reference_modular]
8 | import { doc } from "firebase/firestore";
9 |
10 | const messageRef = doc(db, "rooms", "roomA", "messages", "message1");
11 | // [END subcollection_reference_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/index/analytics_log_event.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_log_event_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | const analytics = getAnalytics();
11 | logEvent(analytics, 'notification_received');
12 | // [END analytics_log_event_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/order_and_limit_desc.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START order_and_limit_desc_modular]
8 | import { query, orderBy, limit } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, orderBy("name", "desc"), limit(3));
11 | // [END order_and_limit_desc_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/file-metadata/storage_custom_metadata.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/file-metadata.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_custom_metadata_modular]
8 | const metadata = {
9 | customMetadata: {
10 | 'location': 'Yosemite, CA, USA',
11 | 'activity': 'Hiking'
12 | }
13 | };
14 | // [END storage_custom_metadata_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/google-signin/auth_google_provider_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/google-signin.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_google_provider_credential_modular]
8 | import { GoogleAuthProvider } from "firebase/auth";
9 |
10 | const credential = GoogleAuthProvider.credential(idToken);
11 | // [END auth_google_provider_credential_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/yahoo-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_yahoo_signin_redirect_modular]
8 | import { getAuth, signInWithRedirect } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithRedirect(auth, provider);
12 | // [END auth_yahoo_signin_redirect_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/array_contains_filter.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START array_contains_filter_modular]
8 | import { query, where } from "firebase/firestore";
9 | const q = query(citiesRef, where("regions", "array-contains", "west_coast"));
10 | // [END array_contains_filter_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/set_with_merge.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START set_with_merge_modular]
8 | import { doc, setDoc } from "firebase/firestore";
9 |
10 | const cityRef = doc(db, 'cities', 'BJ');
11 | setDoc(cityRef, { capital: true }, { merge: true });
12 | // [END set_with_merge_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/emulator-suite/auth_emulator_connect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/emulator-suite.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_emulator_connect_modular]
8 | import { getAuth, connectAuthEmulator } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | connectAuthEmulator(auth, "http://127.0.0.1:9099");
12 | // [END auth_emulator_connect_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/facebook/auth_facebook_provider_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/facebook.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_facebook_provider_credential_modular]
8 | import { FacebookAuthProvider } from "firebase/auth";
9 |
10 | const credential = FacebookAuthProvider.credential(accessToken);
11 | // [END auth_facebook_provider_credential_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/microsoft-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_msft_signin_redirect_modular]
8 | import { getAuth, signInWithRedirect } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithRedirect(auth, provider);
12 | // [END auth_msft_signin_redirect_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/twitter/auth_twitter_provider_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/twitter.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_twitter_provider_credential_modular]
8 | import { TwitterAuthProvider } from "firebase/auth";
9 |
10 | const credential = TwitterAuthProvider.credential(accessToken, secret);
11 | // [END auth_twitter_provider_credential_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/index/auth_make_google_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_make_google_credential_modular]
8 | import { GoogleAuthProvider } from "firebase/auth";
9 |
10 | const credential = GoogleAuthProvider.credential(
11 | googleUser.getAuthResponse().id_token);
12 | // [END auth_make_google_credential_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/link-multiple-accounts/auth_make_email_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/link-multiple-accounts.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_make_email_credential_modular]
8 | import { EmailAuthProvider } from "firebase/auth";
9 |
10 | const credential = EmailAuthProvider.credential(email, password);
11 | // [END auth_make_email_credential_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/in_filter_with_array.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START in_filter_with_array_modular]
8 | import { query, where } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, where('regions', 'in', [['west_coast'], ['east_coast']]));
11 | // [END in_filter_with_array_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/invalid_range_filters.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START invalid_range_filters_modular]
8 | import { query, where } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, where("state", ">=", "CA"), where("population", ">", 100000));
11 | // [END invalid_range_filters_modular]
--------------------------------------------------------------------------------
/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./remoteconfig-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rc_set_minimum_fetch_time_modular]
8 | // The default and recommended production fetch interval for Remote Config is 12 hours
9 | remoteConfig.settings.minimumFetchIntervalMillis = 3600000;
10 | // [END rc_set_minimum_fetch_time_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/index/auth_make_facebook_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_make_facebook_credential_modular]
8 | import { FacebookAuthProvider } from "firebase/auth";
9 |
10 | const credential = FacebookAuthProvider.credential(
11 | response.authResponse.accessToken);
12 | // [END auth_make_facebook_credential_modular]
--------------------------------------------------------------------------------
/snippets/database-next/offline/rtdb_ondisconnect_callback.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/offline.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_ondisconnect_callback_modular]
8 | onDisconnect(presenceRef).remove().catch((err) => {
9 | if (err) {
10 | console.error("could not establish onDisconnect event", err);
11 | }
12 | });
13 | // [END rtdb_ondisconnect_callback_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/count_aggregate_collection.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START count_aggregate_collection_modular]
8 | const coll = collection(db, "cities");
9 | const snapshot = await getCountFromServer(coll);
10 | console.log('count: ', snapshot.data().count);
11 | // [END count_aggregate_collection_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/filter_and_order.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START filter_and_order_modular]
8 | import { query, where, orderBy, limit } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, where("population", ">", 100000), orderBy("population"), limit(2));
11 | // [END filter_and_order_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/or_query.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START or_query_modular]
8 | const q = query(collection(db, "cities"), and(
9 | where('state', '==', 'CA'),
10 | or(
11 | where('capital', '==', true),
12 | where('population', '>=', 1000000)
13 | )
14 | ));
15 | // [END or_query_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/index/auth_sign_out.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/index.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_out_modular]
8 | import { getAuth, signOut } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signOut(auth).then(() => {
12 | // Sign-out successful.
13 | }).catch((error) => {
14 | // An error happened.
15 | });
16 | // [END auth_sign_out_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/invalid_filter_and_order.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START invalid_filter_and_order_modular]
8 | import { query, where, orderBy } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, where("population", ">", 100000), orderBy("country"));
11 | // [END invalid_filter_and_order_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/valid_filter_and_order.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START valid_filter_and_order_modular]
8 | import { query, where, orderBy } from "firebase/firestore";
9 |
10 | const q = query(citiesRef, where("population", ">", 100000), orderBy("population"));
11 | // [END valid_filter_and_order_modular]
--------------------------------------------------------------------------------
/snippets/perf-next/index/perf_add_custom_trace.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./perf-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START perf_add_custom_trace_modular]
8 | import { trace } from "firebase/performance";
9 |
10 | const t = trace(perf, "CUSTOM_TRACE_NAME");
11 | t.start();
12 |
13 | // Code that you want to trace
14 | // ...
15 |
16 | t.stop();
17 | // [END perf_add_custom_trace_modular]
--------------------------------------------------------------------------------
/storage-next/emulator-suite.js:
--------------------------------------------------------------------------------
1 | // [SNIPPET_REGISTRY disabled]
2 | // [SNIPPETS_SEPARATION enabled]
3 |
4 | function onDocumentReady() {
5 | // [START storage_emulator_connect]
6 | const { getStorage, connectStorageEmulator } = require("firebase/storage");
7 |
8 | const storage = getStorage();
9 | if (location.hostname === "localhost") {
10 | // Point to the Storage emulator running on localhost.
11 | connectStorageEmulator(storage, "127.0.0.1", 9199);
12 | }
13 | // [END storage_emulator_connect]
14 | }
15 |
--------------------------------------------------------------------------------
/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_params.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/yahoo-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_yahoo_provider_params_modular]
8 | provider.setCustomParameters({
9 | // Prompt user to re-authenticate to Yahoo.
10 | prompt: 'login',
11 | // Localize to French.
12 | language: 'fr'
13 | });
14 | // [END auth_yahoo_provider_params_modular]
--------------------------------------------------------------------------------
/snippets/database-next/lists-of-data/rtdb_social_recent.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/lists-of-data.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_social_recent_modular]
8 | import { getDatabase, ref, query, limitToLast } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | const recentPostsRef = query(ref(db, 'posts'), limitToLast(100));
12 | // [END rtdb_social_recent_modular]
--------------------------------------------------------------------------------
/snippets/database-next/offline/rtdb_ondisconnect_cancel.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/offline.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_ondisconnect_cancel_modular]
8 | const onDisconnectRef = onDisconnect(presenceRef);
9 | onDisconnectRef.set("I disconnected");
10 | // some time later when we change our minds
11 | onDisconnectRef.cancel();
12 | // [END rtdb_ondisconnect_cancel_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/four_disjunctions_compact.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START four_disjunctions_compact_modular]
8 | query(collectionRef,
9 | and( or( where("a", "==", 1), where("b", "==", 2) ),
10 | or( where("c", "==", 3), where("d", "==", 4) )
11 | )
12 | );
13 | // [END four_disjunctions_compact_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/fs_setup_cache.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START fs_setup_cache_modular]
8 | import { initializeFirestore, CACHE_SIZE_UNLIMITED } from "firebase/firestore";
9 |
10 | const firestoreDb = initializeFirestore(app, {
11 | cacheSizeBytes: CACHE_SIZE_UNLIMITED
12 | });
13 | // [END fs_setup_cache_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/listen_document.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START listen_document_modular]
8 | import { doc, onSnapshot } from "firebase/firestore";
9 |
10 | const unsub = onSnapshot(doc(db, "cities", "SF"), (doc) => {
11 | console.log("Current data: ", doc.data());
12 | });
13 | // [END listen_document_modular]
--------------------------------------------------------------------------------
/auth-next/anonymous.js:
--------------------------------------------------------------------------------
1 | // [SNIPPET_REGISTRY disabled]
2 | // [SNIPPETS_SEPARATION enabled]
3 |
4 | function anonSignIn() {
5 | // [START auth_anon_sign_in]
6 | const { getAuth, signInAnonymously } = require("firebase/auth");
7 |
8 | const auth = getAuth();
9 | signInAnonymously(auth)
10 | .then(() => {
11 | // Signed in..
12 | })
13 | .catch((error) => {
14 | const errorCode = error.code;
15 | const errorMessage = error.message;
16 | // ...
17 | });
18 | // [END auth_anon_sign_in]
19 | }
20 |
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/enable_network.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START enable_network_modular]
8 | import { enableNetwork } from "firebase/firestore";
9 |
10 | await enableNetwork(db);
11 | // Do online actions
12 | // [START_EXCLUDE]
13 | console.log("Network enabled!");
14 | // [END_EXCLUDE]
15 | // [END enable_network_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/simple_queries_again.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START simple_queries_again_modular]
8 | import { collection, query, where } from "firebase/firestore";
9 | const citiesRef = collection(db, "cities");
10 |
11 | const q = query(citiesRef, where("capital", "==", true));
12 | // [END simple_queries_again_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/index/analytics_set_user_properties.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_set_user_properties_modular]
8 | import { getAnalytics, setUserProperties } from "firebase/analytics";
9 |
10 | const analytics = getAnalytics();
11 | setUserProperties(analytics, { favorite_food: 'apples' });
12 | // [END analytics_set_user_properties_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/service-worker-sessions/auth_svc_register.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/service-worker-sessions.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_svc_register_modular]
8 | // Install servicerWorker if supported on sign-in/sign-up page.
9 | if ('serviceWorker' in navigator) {
10 | navigator.serviceWorker.register('/service-worker.js', {scope: '/'});
11 | }
12 | // [END auth_svc_register_modular]
--------------------------------------------------------------------------------
/snippets/database-next/emulator-suite/rtdb_emulator_flush.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/emulator-suite.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_emulator_flush_modular]
8 | import { getDatabase, ref, set } from "firebase/database";
9 |
10 | // With a database Reference, write null to clear the database.
11 | const db = getDatabase();
12 | set(ref(db), null);
13 | // [END rtdb_emulator_flush_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/array_contains_any_filter.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START array_contains_any_filter_modular]
8 | import { query, where } from "firebase/firestore";
9 |
10 | const q = query(citiesRef,
11 | where('regions', 'array-contains-any', [['west_coast'], ['east_coast']]));
12 | // [END array_contains_any_filter_modular]
--------------------------------------------------------------------------------
/storage/delete-files.js:
--------------------------------------------------------------------------------
1 | import firebase from "firebase/app";
2 | import "firebase/storage";
3 |
4 | function deleteFile() {
5 | const storageRef = firebase.storage().ref();
6 |
7 | // [START storage_delete_file]
8 | // Create a reference to the file to delete
9 | var desertRef = storageRef.child('images/desert.jpg');
10 |
11 | // Delete the file
12 | desertRef.delete().then(() => {
13 | // File deleted successfully
14 | }).catch((error) => {
15 | // Uh-oh, an error occurred!
16 | });
17 | // [END storage_delete_file]
18 | }
19 |
--------------------------------------------------------------------------------
/snippets/analytics-next/index/analytics_log_event_custom_params.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_log_event_custom_params_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | const analytics = getAnalytics();
11 | logEvent(analytics, 'goal_completion', { name: 'lever_puzzle'});
12 | // [END analytics_log_event_custom_params_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-arrays/post_with_array.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-arrays.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START post_with_array_modular]
8 | // Sample document in the 'posts' collection.
9 | {
10 | title: "My great post",
11 | categories: [
12 | "technology",
13 | "opinion",
14 | "cats"
15 | ]
16 | }
17 | // [END post_with_array_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/index/auth_set_language_code.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_set_language_code_modular]
8 | import { getAuth } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | auth.languageCode = 'it';
12 | // To apply the default browser preference instead of explicitly setting it.
13 | // auth.useDeviceLanguage();
14 | // [END auth_set_language_code_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/microsoft-oauth/auth_msft_provider_params.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/microsoft-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_msft_provider_params_modular]
8 | provider.setCustomParameters({
9 | // Force re-consent.
10 | prompt: 'consent',
11 | // Target specific email with login hint.
12 | login_hint: 'user@firstadd.onmicrosoft.com'
13 | });
14 | // [END auth_msft_provider_params_modular]
--------------------------------------------------------------------------------
/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/lists-of-data.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_social_most_viewed_modular]
8 | import { getDatabase, ref, query, orderByChild } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | const mostViewedPosts = query(ref(db, 'posts'), orderByChild('metrics/views'));
12 | // [END rtdb_social_most_viewed_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/count_aggregate_query.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START count_aggregate_query_modular]
8 | const coll = collection(db, "cities");
9 | const q = query(coll, where("state", "==", "CA"));
10 | const snapshot = await getCountFromServer(q);
11 | console.log('count: ', snapshot.data().count);
12 | // [END count_aggregate_query_modular]
--------------------------------------------------------------------------------
/snippets/remoteconfig-next/index/rc_fetch_config_callback.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./remoteconfig-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rc_fetch_config_callback_modular]
8 | import { fetchAndActivate } from "firebase/remote-config";
9 |
10 | fetchAndActivate(remoteConfig)
11 | .then(() => {
12 | // ...
13 | })
14 | .catch((err) => {
15 | // ...
16 | });
17 | // [END rc_fetch_config_callback_modular]
--------------------------------------------------------------------------------
/snippets/firebaseapp-next/firebaseapp/firebase_secondary.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firebaseapp-next/firebaseapp.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START firebase_secondary_modular]
8 | // Initialize another app with a different config
9 | const secondaryApp = initializeApp(secondaryAppConfig, "secondary");
10 | // Access services, such as the Realtime Database
11 | // getDatabase(secondaryApp)
12 | // [END firebase_secondary_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/get_all_users.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START get_all_users_modular]
8 | import { collection, getDocs } from "firebase/firestore";
9 |
10 | const querySnapshot = await getDocs(collection(db, "users"));
11 | querySnapshot.forEach((doc) => {
12 | console.log(`${doc.id} => ${doc.data()}`);
13 | });
14 | // [END get_all_users_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/new_document.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START new_document_modular]
8 | import { collection, doc, setDoc } from "firebase/firestore";
9 |
10 | // Add a new document with a generated id
11 | const newCityRef = doc(collection(db, "cities"));
12 |
13 | // later...
14 | await setDoc(newCityRef, data);
15 | // [END new_document_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/set_document.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START set_document_modular]
8 | import { doc, setDoc } from "firebase/firestore";
9 |
10 | // Add a new document in collection "cities"
11 | await setDoc(doc(db, "cities", "LA"), {
12 | name: "Los Angeles",
13 | state: "CA",
14 | country: "USA"
15 | });
16 | // [END set_document_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-arrays/post_with_map.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-arrays.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START post_with_map_modular]
8 | // Sample document in the 'posts' collection
9 | {
10 | title: "My great post",
11 | categories: {
12 | "technology": true,
13 | "opinion": true,
14 | "cats": true
15 | }
16 | }
17 | // [END post_with_map_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/phone-auth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_phone_recaptcha_verifier_simple_modular]
8 | import { getAuth, RecaptchaVerifier } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | window.recaptchaVerifier = new RecaptchaVerifier(auth, 'recaptcha-container', {});
12 | // [END auth_phone_recaptcha_verifier_simple_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/example_filters.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START example_filters_modular]
8 | const stateQuery = query(citiesRef, where("state", "==", "CA"));
9 | const populationQuery = query(citiesRef, where("population", "<", 100000));
10 | const nameQuery = query(citiesRef, where("name", ">=", "San Francisco"));
11 | // [END example_filters_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/listen_with_metadata.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START listen_with_metadata_modular]
8 | import { doc, onSnapshot } from "firebase/firestore";
9 |
10 | const unsub = onSnapshot(
11 | doc(db, "cities", "SF"),
12 | { includeMetadataChanges: true },
13 | (doc) => {
14 | // ...
15 | });
16 | // [END listen_with_metadata_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/set_custom_object.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START set_custom_object_modular]
8 | import { doc, setDoc } from "firebase/firestore";
9 |
10 | // Set with cityConverter
11 | const ref = doc(db, "cities", "LA").withConverter(cityConverter);
12 | await setDoc(ref, new City("Los Angeles", "CA", "USA"));
13 | // [END set_custom_object_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/index/analytics_log_event_params.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_log_event_params_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | const analytics = getAnalytics();
11 | logEvent(analytics, 'select_content', {
12 | content_type: 'image',
13 | content_id: 'P12453'
14 | });
15 | // [END analytics_log_event_params_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/multi-tenancy/multitenant_switch_tenant.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/multi-tenancy.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START multitenant_switch_tenant_modular]
8 | // One Auth instance
9 | // Switch to tenant1
10 | auth.tenantId = "TENANT_ID1";
11 | // Switch to tenant2
12 | auth.tenantId = "TENANT_ID2";
13 | // Switch back to project level IdPs
14 | auth.tenantId = null;
15 | // [END multitenant_switch_tenant_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/update_document.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START update_document_modular]
8 | import { doc, updateDoc } from "firebase/firestore";
9 |
10 | const washingtonRef = doc(db, "cities", "DC");
11 |
12 | // Set the "capital" field of the city 'DC'
13 | await updateDoc(washingtonRef, {
14 | capital: true
15 | });
16 | // [END update_document_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/email/auth_send_email_verification.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/email.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_send_email_verification_modular]
8 | import { getAuth, sendEmailVerification } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | sendEmailVerification(auth.currentUser)
12 | .then(() => {
13 | // Email verification sent!
14 | // ...
15 | });
16 | // [END auth_send_email_verification_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/manage/auth_delete_user.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/manage.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_delete_user_modular]
8 | import { getAuth, deleteUser } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | const user = auth.currentUser;
12 |
13 | deleteUser(user).then(() => {
14 | // User deleted.
15 | }).catch((error) => {
16 | // An error ocurred
17 | // ...
18 | });
19 | // [END auth_delete_user_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_scopes.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/yahoo-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_yahoo_provider_scopes_modular]
8 | // Request access to Yahoo Mail API.
9 | provider.addScope('mail-r');
10 | // Request read/write access to user contacts.
11 | // This must be preconfigured in the app's API permissions.
12 | provider.addScope('sdct-w');
13 | // [END auth_yahoo_provider_scopes_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/chain_filters.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START chain_filters_modular]
8 | import { query, where } from "firebase/firestore";
9 |
10 | const q1 = query(citiesRef, where("state", "==", "CO"), where("name", "==", "Denver"));
11 | const q2 = query(citiesRef, where("state", "==", "CA"), where("population", "<", 1000000));
12 | // [END chain_filters_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/disable_network.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START disable_network_modular]
8 | import { disableNetwork } from "firebase/firestore";
9 |
10 | await disableNetwork(db);
11 | console.log("Network disabled!");
12 | // Do offline actions
13 | // [START_EXCLUDE]
14 | console.log("Network disabled!");
15 | // [END_EXCLUDE]
16 | // [END disable_network_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-aggregation.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START get_collection_ratings_modular]
8 | import { collection, getDocs } from "firebase/firestore";
9 |
10 | const ratingsRef = collection(db, "restaurants", "arinell-pizza", "ratings");
11 | const ratingsDocs = await getDocs(ratingsRef);
12 | // [END get_collection_ratings_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/emulator-suite/fs_emulator_connect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/emulator-suite.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START fs_emulator_connect_modular]
8 | import { getFirestore, connectFirestoreEmulator } from "firebase/firestore";
9 |
10 | // firebaseApps previously initialized using initializeApp()
11 | const db = getFirestore();
12 | connectFirestoreEmulator(db, '127.0.0.1', 8080);
13 | // [END fs_emulator_connect_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/handle_listen_errors.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START handle_listen_errors_modular]
8 | import { collection, onSnapshot } from "firebase/firestore";
9 |
10 | const unsubscribe = onSnapshot(
11 | collection(db, "cities"),
12 | (snapshot) => {
13 | // ...
14 | },
15 | (error) => {
16 | // ...
17 | });
18 | // [END handle_listen_errors_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-arrays.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START query_in_category_timestamp_modular]
8 | import { collection, query, where, orderBy } from "firebase/firestore";
9 |
10 | const q = query(collection(db, "posts"),
11 | where("categories.cats", ">", 0),
12 | orderBy("categories.cats"));
13 | // [END query_in_category_timestamp_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/index/storage_multiple_buckets.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_multiple_buckets_modular]
8 | import { getApp } from "firebase/app";
9 | import { getStorage } from "firebase/storage";
10 |
11 | // Get a non-default Storage bucket
12 | const firebaseApp = getApp();
13 | const storage = getStorage(firebaseApp, "gs://my-custom-bucket");
14 | // [END storage_multiple_buckets_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/index/analytics_record_screen_view.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_record_screen_view_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | const analytics = getAnalytics();
11 | logEvent(analytics, 'screen_view', {
12 | firebase_screen: screenName,
13 | firebase_screen_class: screenClass
14 | });
15 | // [END analytics_record_screen_view_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/valid_range_filters.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START valid_range_filters_modular]
8 | import { query, where } from "firebase/firestore";
9 |
10 | const q1 = query(citiesRef, where("state", ">=", "CA"), where("state", "<=", "IN"));
11 | const q2 = query(citiesRef, where("state", "==", "CA"), where("population", ">", 1000000));
12 | // [END valid_range_filters_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/manage/auth_update_user_email.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/manage.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_update_user_email_modular]
8 | import { getAuth, updateEmail } from "firebase/auth";
9 | const auth = getAuth();
10 | updateEmail(auth.currentUser, "user@example.com").then(() => {
11 | // Email updated!
12 | // ...
13 | }).catch((error) => {
14 | // An error occurred
15 | // ...
16 | });
17 | // [END auth_update_user_email_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/multi-tenancy/multitenant_signin_custom_token.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/multi-tenancy.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START multitenant_signin_custom_token_modular]
8 | import { signInWithCustomToken } from "firebase/auth";
9 | auth.tenantId = 'TENANT_ID1';
10 |
11 | signInWithCustomToken(auth, token)
12 | .catch((error) => {
13 | // Handle / display error.
14 | // ...
15 | });
16 | // [END multitenant_signin_custom_token_modular]
--------------------------------------------------------------------------------
/snippets/database-next/offline/rtdb_set_server_timestamp.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/offline.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_set_server_timestamp_modular]
8 | import { getDatabase, ref, onDisconnect, serverTimestamp } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | const userLastOnlineRef = ref(db, "users/joe/lastOnline");
12 | onDisconnect(userLastOnlineRef).set(serverTimestamp());
13 | // [END rtdb_set_server_timestamp_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/update_delete_field.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START update_delete_field_modular]
8 | import { doc, updateDoc, deleteField } from "firebase/firestore";
9 |
10 | const cityRef = doc(db, 'cities', 'BJ');
11 |
12 | // Remove the 'capital' field from the document
13 | await updateDoc(cityRef, {
14 | capital: deleteField()
15 | });
16 | // [END update_delete_field_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-arrays.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START post_with_map_advanced_modular]
8 | // The value of each entry in 'categories' is a unix timestamp
9 | {
10 | title: "My great post",
11 | categories: {
12 | technology: 1502144665,
13 | opinion: 1502144665,
14 | cats: 1502144665
15 | }
16 | }
17 | // [END post_with_map_advanced_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/detach_listener.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START detach_listener_modular]
8 | import { collection, onSnapshot } from "firebase/firestore";
9 |
10 | const unsubscribe = onSnapshot(collection(db, "cities"), () => {
11 | // Respond to data
12 | // ...
13 | });
14 |
15 | // Later ...
16 |
17 | // Stop listening to changes
18 | unsubscribe();
19 | // [END detach_listener_modular]
--------------------------------------------------------------------------------
/snippets/perf-next/index/perf_initialize_app.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./perf-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START perf_initialize_app_modular]
8 | // TODO: Replace the following with your app's Firebase project configuration
9 | // See: https://firebase.google.com/docs/web/learn-more#config-object
10 | const firebaseConfig = {
11 | // ...
12 | };
13 |
14 | // Initialize Firebase
15 | const app = initializeApp(firebaseConfig);
16 | // [END perf_initialize_app_modular]
--------------------------------------------------------------------------------
/snippets/perf-next/index/perf_user_timing_marks.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./perf-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START perf_user_timing_marks_modular]
8 | const performance = window.performance;
9 |
10 | performance.mark("measurementStart");
11 |
12 | // Code that you want to trace
13 | // ...
14 |
15 | performance.mark("measurementStop");
16 | performance.measure("customTraceName", "measurementStart", "measurementStop");
17 | // [END perf_user_timing_marks_modular]
--------------------------------------------------------------------------------
/auth/anonymous.js:
--------------------------------------------------------------------------------
1 | // These samples are intended for Web so this import would normally be
2 | // done in HTML however using modules here is more convenient for
3 | // ensuring sample correctness offline.
4 | import firebase from "firebase/app";
5 | import "firebase/auth";
6 |
7 | function anonSignIn() {
8 | // [START auth_anon_sign_in]
9 | firebase.auth().signInAnonymously()
10 | .then(() => {
11 | // Signed in..
12 | })
13 | .catch((error) => {
14 | var errorCode = error.code;
15 | var errorMessage = error.message;
16 | // ...
17 | });
18 | // [END auth_anon_sign_in]
19 | }
20 |
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/add_document.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START add_document_modular]
8 | import { collection, addDoc } from "firebase/firestore";
9 |
10 | // Add a new document with a generated id.
11 | const docRef = await addDoc(collection(db, "cities"), {
12 | name: "Tokyo",
13 | country: "Japan"
14 | });
15 | console.log("Document written with ID: ", docRef.id);
16 | // [END add_document_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/listen_document_local.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START listen_document_local_modular]
8 | import { doc, onSnapshot } from "firebase/firestore";
9 |
10 | const unsub = onSnapshot(doc(db, "cities", "SF"), (doc) => {
11 | const source = doc.metadata.hasPendingWrites ? "Local" : "Server";
12 | console.log(source, " data: ", doc.data());
13 | });
14 | // [END listen_document_local_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/simple_queries.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START simple_queries_modular]
8 | // Create a reference to the cities collection
9 | import { collection, query, where } from "firebase/firestore";
10 | const citiesRef = collection(db, "cities");
11 |
12 | // Create a query against the collection.
13 | const q = query(citiesRef, where("state", "==", "CA"));
14 | // [END simple_queries_modular]
--------------------------------------------------------------------------------
/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./functions-next/emulator-suite.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START fb_functions_emulator_connect_modular]
8 | import { getApp } from "firebase/app";
9 | import { getFunctions, connectFunctionsEmulator } from "firebase/functions";
10 |
11 | const functions = getFunctions(getApp());
12 | connectFunctionsEmulator(functions, "127.0.0.1", 5001);
13 | // [END fb_functions_emulator_connect_modular]
--------------------------------------------------------------------------------
/storage/emulator-suite.js:
--------------------------------------------------------------------------------
1 | // These samples are intended for Web so this import would normally be
2 | // done in HTML however using modules here is more convenient for
3 | // ensuring sample correctness offline.
4 | import firebase from "firebase/app";
5 | import "firebase/storage";
6 |
7 | function onDocumentReady() {
8 | // [START storage_emulator_connect]
9 | var storage = firebase.storage();
10 | if (location.hostname === "localhost") {
11 | // Point to the Storage emulator running on localhost.
12 | storage.useEmulator("127.0.0.1", 9199);
13 | }
14 | // [END storage_emulator_connect]
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/snippets/database-next/offline/rtdb_ondisconnect_simple.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/offline.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_ondisconnect_simple_modular]
8 | import { getDatabase, ref, onDisconnect } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | const presenceRef = ref(db, "disconnectmessage");
12 | // Write a string when this client loses connection
13 | onDisconnect(presenceRef).set("I disconnected!");
14 | // [END rtdb_ondisconnect_simple_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/four_disjunctions.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START four_disjunctions_modular]
8 | query(collectionRef,
9 | or( and( where("a", "==", 1), where("c", "==", 3) ),
10 | and( where("a", "==", 1), where("d", "==", 4) ),
11 | and( where("b", "==", 2), where("c", "==", 3) ),
12 | and( where("b", "==", 2), where("d", "==", 4) )
13 | )
14 | );
15 | // [END four_disjunctions_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/manage/send_email_verification.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/manage.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START send_email_verification_modular]
8 | import { getAuth, sendEmailVerification } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | const user = auth.currentUser;
12 |
13 | sendEmailVerification(user).then(() => {
14 | // Email sent.
15 | }).catch((error) => {
16 | // An error ocurred
17 | // ...
18 | });
19 | // [END send_email_verification_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-arrays.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START query_in_category_timestamp_invalid_modular]
8 | import { collection, query, where, orderBy, Firestore } from "firebase/firestore";
9 |
10 | const q = query(collection(db, "posts"),
11 | where("categories.cats", "==", true),
12 | orderBy("timestamp"));
13 | // [END query_in_category_timestamp_invalid_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/index/storage_custom_app.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_custom_app_modular]
8 | import { getStorage } from "firebase/storage";
9 |
10 | // Get the default bucket from a custom firebase.app.App
11 | const storage1 = getStorage(customApp);
12 |
13 | // Get a non-default bucket from a custom firebase.app.App
14 | const storage2 = getStorage(customApp, "gs://my-custom-bucket");
15 | // [END storage_custom_app_modular]
--------------------------------------------------------------------------------
/storage-next/delete-files.js:
--------------------------------------------------------------------------------
1 | // [SNIPPET_REGISTRY disabled]
2 | // [SNIPPETS_SEPARATION enabled]
3 |
4 | function deleteFile() {
5 | // [START storage_delete_file]
6 | const { getStorage, ref, deleteObject } = require("firebase/storage");
7 |
8 | const storage = getStorage();
9 |
10 | // Create a reference to the file to delete
11 | const desertRef = ref(storage, 'images/desert.jpg');
12 |
13 | // Delete the file
14 | deleteObject(desertRef).then(() => {
15 | // File deleted successfully
16 | }).catch((error) => {
17 | // Uh-oh, an error occurred!
18 | });
19 | // [END storage_delete_file]
20 | }
21 |
--------------------------------------------------------------------------------
/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/link-multiple-accounts.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_link_with_redirect_modular]
8 | import { getAuth, linkWithRedirect, GoogleAuthProvider } from "firebase/auth";
9 | const provider = new GoogleAuthProvider();
10 |
11 | const auth = getAuth();
12 | linkWithRedirect(auth.currentUser, provider)
13 | .then(/* ... */)
14 | .catch(/* ... */);
15 | // [END auth_link_with_redirect_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/phone-auth/auth_phone_verify_code.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/phone-auth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_phone_verify_code_modular]
8 | const code = getCodeFromUserInput();
9 | confirmationResult.confirm(code).then((result) => {
10 | // User signed in successfully.
11 | const user = result.user;
12 | // ...
13 | }).catch((error) => {
14 | // User couldn't sign in (bad verification code?)
15 | // ...
16 | });
17 | // [END auth_phone_verify_code_modular]
--------------------------------------------------------------------------------
/snippets/messaging-next/index/messaging_delete_token.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./messaging-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START messaging_delete_token_modular]
8 | import { getMessaging, deleteToken } from "firebase/messaging";
9 |
10 | const messaging = getMessaging();
11 | deleteToken(messaging).then(() => {
12 | console.log('Token deleted.');
13 | // ...
14 | }).catch((err) => {
15 | console.log('Unable to delete token. ', err);
16 | });
17 | // [END messaging_delete_token_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/link-multiple-accounts.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_unlink_provider_modular]
8 | import { getAuth, unlink } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | unlink(auth.currentUser, providerId).then(() => {
12 | // Auth provider unlinked from account
13 | // ...
14 | }).catch((error) => {
15 | // An error happened
16 | // ...
17 | });
18 | // [END auth_unlink_provider_modular]
--------------------------------------------------------------------------------
/snippets/database-next/emulator-suite/rtdb_emulator_connect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/emulator-suite.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_emulator_connect_modular]
8 | import { getDatabase, connectDatabaseEmulator } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | if (location.hostname === "localhost") {
12 | // Point to the RTDB emulator running on localhost.
13 | connectDatabaseEmulator(db, "127.0.0.1", 9000);
14 | }
15 | // [END rtdb_emulator_connect_modular]
--------------------------------------------------------------------------------
/snippets/database-next/lists-of-data/rtdb_social_push.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/lists-of-data.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_social_push_modular]
8 | import { getDatabase, ref, push, set } from "firebase/database";
9 |
10 | // Create a new post reference with an auto-generated id
11 | const db = getDatabase();
12 | const postListRef = ref(db, 'posts');
13 | const newPostRef = push(postListRef);
14 | set(newPostRef, {
15 | // ...
16 | });
17 | // [END rtdb_social_push_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/get_multiple_all.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START get_multiple_all_modular]
8 | import { collection, getDocs } from "firebase/firestore";
9 |
10 | const querySnapshot = await getDocs(collection(db, "cities"));
11 | querySnapshot.forEach((doc) => {
12 | // doc.data() is never undefined for query doc snapshots
13 | console.log(doc.id, " => ", doc.data());
14 | });
15 | // [END get_multiple_all_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/anonymous/auth_anon_sign_in.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/anonymous.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_anon_sign_in_modular]
8 | import { getAuth, signInAnonymously } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInAnonymously(auth)
12 | .then(() => {
13 | // Signed in..
14 | })
15 | .catch((error) => {
16 | const errorCode = error.code;
17 | const errorMessage = error.message;
18 | // ...
19 | });
20 | // [END auth_anon_sign_in_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/service-worker-sessions.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_svc_get_idtoken_modular]
8 | import { getAuth, getIdToken } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | getIdToken(auth.currentUser)
12 | .then((idToken) => {
13 | // idToken can be passed back to server.
14 | })
15 | .catch((error) => {
16 | // Error occurred.
17 | });
18 | // [END auth_svc_get_idtoken_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/update_document_increment.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START update_document_increment_modular]
8 | import { doc, updateDoc, increment } from "firebase/firestore";
9 |
10 | const washingtonRef = doc(db, "cities", "DC");
11 |
12 | // Atomically increment the population of the city by 50.
13 | await updateDoc(washingtonRef, {
14 | population: increment(50)
15 | });
16 | // [END update_document_increment_modular]
--------------------------------------------------------------------------------
/auth/emulator-suite.js:
--------------------------------------------------------------------------------
1 | import firebase from "firebase/app";
2 | import "firebase/auth";
3 |
4 | function emulatorConnect() {
5 | // [START auth_emulator_connect]
6 | const auth = firebase.auth();
7 | auth.useEmulator("http://127.0.0.1:9099");
8 | // [END auth_emulator_connect]
9 | }
10 |
11 | function emulatorGoogleCredential() {
12 | // [START auth_emulator_google_credential]
13 | const auth = firebase.auth();
14 | auth.signInWithCredential(firebase.auth.GoogleAuthProvider.credential(
15 | '{"sub": "abc123", "email": "foo@example.com", "email_verified": true}'
16 | ));
17 | // [END auth_emulator_google_credential]
18 | }
19 |
--------------------------------------------------------------------------------
/snippets/auth-next/emulator-suite/auth_emulator_google_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/emulator-suite.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_emulator_google_credential_modular]
8 | import { getAuth, signInWithCredential, GoogleAuthProvider } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithCredential(auth, GoogleAuthProvider.credential(
12 | '{"sub": "abc123", "email": "foo@example.com", "email_verified": true}'
13 | ));
14 | // [END auth_emulator_google_credential_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/manage/auth_send_password_reset.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/manage.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_send_password_reset_modular]
8 | import { getAuth, sendPasswordResetEmail } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | const emailAddress = "user@example.com";
12 |
13 | sendPasswordResetEmail(auth, emailAddress).then(() => {
14 | // Email sent.
15 | }).catch((error) => {
16 | // An error ocurred
17 | // ...
18 | });
19 | // [END auth_send_password_reset_modular]
--------------------------------------------------------------------------------
/snippets/database-next/read-and-write/rtdb_write_new_user.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/read-and-write.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_write_new_user_modular]
8 | import { getDatabase, ref, set } from "firebase/database";
9 |
10 | function writeUserData(userId, name, email, imageUrl) {
11 | const db = getDatabase();
12 | set(ref(db, 'users/' + userId), {
13 | username: name,
14 | email: email,
15 | profile_picture : imageUrl
16 | });
17 | }
18 | // [END rtdb_write_new_user_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/create-reference/storage_create_ref.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/create-reference.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_create_ref_modular]
8 | import { getStorage, ref } from "firebase/storage";
9 |
10 | // Get a reference to the storage service, which is used to create references in your storage bucket
11 | const storage = getStorage();
12 |
13 | // Create a storage reference from our storage service
14 | const storageRef = ref(storage);
15 | // [END storage_create_ref_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/emulator-suite/storage_emulator_connect.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/emulator-suite.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_emulator_connect_modular]
8 | import { getStorage, connectStorageEmulator } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 | if (location.hostname === "localhost") {
12 | // Point to the Storage emulator running on localhost.
13 | connectStorageEmulator(storage, "127.0.0.1", 9199);
14 | }
15 | // [END storage_emulator_connect_modular]
--------------------------------------------------------------------------------
/snippets/database-next/offline/rtdb_estimate_clock_skew.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/offline.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_estimate_clock_skew_modular]
8 | import { getDatabase, ref, onValue } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | const offsetRef = ref(db, ".info/serverTimeOffset");
12 | onValue(offsetRef, (snap) => {
13 | const offset = snap.val();
14 | const estimatedServerTimeMs = new Date().getTime() + offset;
15 | });
16 | // [END rtdb_estimate_clock_skew_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/index/auth_current_user.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_current_user_modular]
8 | import { getAuth } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | const user = auth.currentUser;
12 |
13 | if (user) {
14 | // User is signed in, see docs for a list of available properties
15 | // https://firebase.google.com/docs/reference/js/auth.user
16 | // ...
17 | } else {
18 | // No user is signed in.
19 | }
20 | // [END auth_current_user_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/index/auth_init_custom_domain.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_init_custom_domain_modular]
8 | import { initializeApp } from "firebase/app";
9 |
10 | const firebaseConfig = {
11 | apiKey: "...",
12 | // By default, authDomain is '[YOUR_APP].firebaseapp.com'.
13 | // You may replace it with a custom domain.
14 | authDomain: '[YOUR_CUSTOM_DOMAIN]'
15 | };
16 | const firebaseApp = initializeApp(firebaseConfig);
17 | // [END auth_init_custom_domain_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-arrays/query_in_category.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-arrays.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START query_in_category_modular]
8 | import { collection, getDocs, query, where } from "firebase/firestore";
9 |
10 | // Find all documents in the 'posts' collection that are
11 | // in the 'cats' category.
12 | const q = query(collection(db, "posts"), where("categories.cats", "==", true));
13 | const docs = await getDocs(q);
14 | // ...
15 | // [END query_in_category_modular]
--------------------------------------------------------------------------------
/auth-next/custom.js:
--------------------------------------------------------------------------------
1 | // [SNIPPET_REGISTRY disabled]
2 | // [SNIPPETS_SEPARATION enabled]
3 |
4 | function signInCustom() {
5 | const token = "token123";
6 |
7 | // [START auth_sign_in_custom]
8 | const { getAuth, signInWithCustomToken } = require("firebase/auth");
9 |
10 | const auth = getAuth();
11 | signInWithCustomToken(auth, token)
12 | .then((userCredential) => {
13 | // Signed in
14 | const user = userCredential.user;
15 | // ...
16 | })
17 | .catch((error) => {
18 | const errorCode = error.code;
19 | const errorMessage = error.message;
20 | // ...
21 | });
22 | // [END auth_sign_in_custom]
23 | }
24 |
--------------------------------------------------------------------------------
/snippets/storage-next/upload-files/storage_upload_blob.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/upload-files.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_upload_blob_modular]
8 | import { getStorage, ref, uploadBytes } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 | const storageRef = ref(storage, 'some-child');
12 |
13 | // 'file' comes from the Blob or File API
14 | uploadBytes(storageRef, file).then((snapshot) => {
15 | console.log('Uploaded a blob or file!');
16 | });
17 | // [END storage_upload_blob_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/update_with_server_timestamp.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START update_with_server_timestamp_modular]
8 | import { updateDoc, serverTimestamp } from "firebase/firestore";
9 |
10 | const docRef = doc(db, 'objects', 'some-id');
11 |
12 | // Update the timestamp field with the value from the server
13 | const updateTimestamp = await updateDoc(docRef, {
14 | timestamp: serverTimestamp()
15 | });
16 | // [END update_with_server_timestamp_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/custom-dependencies/auth_only_indexed_db.js:
--------------------------------------------------------------------------------
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]
--------------------------------------------------------------------------------
/snippets/auth-next/manage/auth_update_password.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/manage.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_update_password_modular]
8 | import { getAuth, updatePassword } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 |
12 | const user = auth.currentUser;
13 | const newPassword = getASecureRandomPassword();
14 |
15 | updatePassword(user, newPassword).then(() => {
16 | // Update successful.
17 | }).catch((error) => {
18 | // An error ocurred
19 | // ...
20 | });
21 | // [END auth_update_password_modular]
--------------------------------------------------------------------------------
/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/read-and-write.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_social_listen_star_count_modular]
8 | import { getDatabase, ref, onValue } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | const starCountRef = ref(db, 'posts/' + postId + '/starCount');
12 | onValue(starCountRef, (snapshot) => {
13 | const data = snapshot.val();
14 | updateStarCount(postElement, data);
15 | });
16 | // [END rtdb_social_listen_star_count_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/get_document.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START get_document_modular]
8 | import { doc, getDoc } from "firebase/firestore";
9 |
10 | const docRef = doc(db, "cities", "SF");
11 | const docSnap = await getDoc(docRef);
12 |
13 | if (docSnap.exists()) {
14 | console.log("Document data:", docSnap.data());
15 | } else {
16 | // docSnap.data() will be undefined in this case
17 | console.log("No such document!");
18 | }
19 | // [END get_document_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/custom-dependencies/auth_only_browser_local.js:
--------------------------------------------------------------------------------
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]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/start_doc.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START start_doc_modular]
8 | import { collection, doc, getDoc, query, orderBy, startAt } from "firebase/firestore";
9 | const citiesRef = collection(db, "cities");
10 |
11 | const docSnap = await getDoc(doc(citiesRef, "SF"));
12 |
13 | // Get all cities with a population bigger than San Francisco
14 | const biggerThanSf = query(citiesRef, orderBy("population"), startAt(docSnap));
15 | // ...
16 | // [END start_doc_modular]
--------------------------------------------------------------------------------
/snippets/functions-next/callable/fb_functions_initialize.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./functions-next/callable.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START fb_functions_initialize_modular]
8 | import { initializeApp } from "firebase/app";
9 | import { getFunctions } from "firebase/functions";
10 |
11 | initializeApp({
12 | // Your Firebase Web SDK configuration
13 | // [START_EXCLUDE]
14 | projectId: "",
15 | apiKey: "",
16 | // [END_EXCLUDE]
17 | });
18 |
19 | const functions = getFunctions();
20 | // [END fb_functions_initialize_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/link-multiple-accounts/auth_get_providers.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/link-multiple-accounts.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_providers_modular]
8 | import { GoogleAuthProvider, FacebookAuthProvider, TwitterAuthProvider, GithubAuthProvider } from "firebase/auth";
9 |
10 | const googleProvider = new GoogleAuthProvider();
11 | const facebookProvider = new FacebookAuthProvider();
12 | const twitterProvider = new TwitterAuthProvider();
13 | const githubProvider = new GithubAuthProvider();
14 | // [END auth_get_providers_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/manage/auth_update_user_profile.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/manage.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_update_user_profile_modular]
8 | import { getAuth, updateProfile } from "firebase/auth";
9 | const auth = getAuth();
10 | updateProfile(auth.currentUser, {
11 | displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg"
12 | }).then(() => {
13 | // Profile updated!
14 | // ...
15 | }).catch((error) => {
16 | // An error occurred
17 | // ...
18 | });
19 | // [END auth_update_user_profile_modular]
--------------------------------------------------------------------------------
/snippets/database-next/lists-of-data/rtdb_social_most_starred.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/lists-of-data.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_social_most_starred_modular]
8 | import { getDatabase, ref, query, orderByChild } from "firebase/database";
9 | import { getAuth } from "firebase/auth";
10 |
11 | const db = getDatabase();
12 | const auth = getAuth();
13 |
14 | const myUserId = auth.currentUser.uid;
15 | const topUserPostsRef = query(ref(db, 'user-posts/' + myUserId), orderByChild('starCount'));
16 | // [END rtdb_social_most_starred_modular]
--------------------------------------------------------------------------------
/snippets/database-next/offline/rtdb_detect_connection_state.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/offline.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_detect_connection_state_modular]
8 | import { getDatabase, ref, onValue } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | const connectedRef = ref(db, ".info/connected");
12 | onValue(connectedRef, (snap) => {
13 | if (snap.val() === true) {
14 | console.log("connected");
15 | } else {
16 | console.log("not connected");
17 | }
18 | });
19 | // [END rtdb_detect_connection_state_modular]
--------------------------------------------------------------------------------
/snippets/firebaseapp-next/firebaseapp/firebase_options.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firebaseapp-next/firebaseapp.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START firebase_options_modular]
8 | import { initializeApp } from "firebase/app";
9 |
10 | // The following fields are REQUIRED:
11 | // - Project ID
12 | // - App ID
13 | // - API Key
14 | const secondaryAppConfig = {
15 | projectId: "",
16 | appId: "",
17 | apiKey: "",
18 | // databaseURL: "...",
19 | // storageBucket: "...",
20 | };
21 | // [END firebase_options_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/fs_collection_group_query.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START fs_collection_group_query_modular]
8 | import { collectionGroup, query, where, getDocs } from "firebase/firestore";
9 |
10 | const museums = query(collectionGroup(db, 'landmarks'), where('type', '==', 'museum'));
11 | const querySnapshot = await getDocs(museums);
12 | querySnapshot.forEach((doc) => {
13 | console.log(doc.id, ' => ', doc.data());
14 | });
15 | // [END fs_collection_group_query_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/get_multiple.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START get_multiple_modular]
8 | import { collection, query, where, getDocs } from "firebase/firestore";
9 |
10 | const q = query(collection(db, "cities"), where("capital", "==", true));
11 |
12 | const querySnapshot = await getDocs(q);
13 | querySnapshot.forEach((doc) => {
14 | // doc.data() is never undefined for query doc snapshots
15 | console.log(doc.id, " => ", doc.data());
16 | });
17 | // [END get_multiple_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/ecommerce.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_ecommerce_remove_cart_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | // Prepare ecommerce params
11 | const params6 = {
12 | currency: 'USD',
13 | value: 24.99,
14 | items: [item_jeggings]
15 | };
16 |
17 | // Log event
18 | const analytics = getAnalytics();
19 | logEvent(analytics, 'remove_from_cart', params6);
20 | // [END analytics_ecommerce_remove_cart_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/email/auth_send_password_reset.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/email.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_send_password_reset_modular]
8 | import { getAuth, sendPasswordResetEmail } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | sendPasswordResetEmail(auth, email)
12 | .then(() => {
13 | // Password reset email sent!
14 | // ..
15 | })
16 | .catch((error) => {
17 | const errorCode = error.code;
18 | const errorMessage = error.message;
19 | // ..
20 | });
21 | // [END auth_send_password_reset_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/add_ada_lovelace.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START add_ada_lovelace_modular]
8 | import { collection, addDoc } from "firebase/firestore";
9 |
10 | try {
11 | const docRef = await addDoc(collection(db, "users"), {
12 | first: "Ada",
13 | last: "Lovelace",
14 | born: 1815
15 | });
16 | console.log("Document written with ID: ", docRef.id);
17 | } catch (e) {
18 | console.error("Error adding document: ", e);
19 | }
20 | // [END add_ada_lovelace_modular]
--------------------------------------------------------------------------------
/snippets/messaging-next/index/messaging_request_permission.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./messaging-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START messaging_request_permission_modular]
8 | Notification.requestPermission().then((permission) => {
9 | if (permission === 'granted') {
10 | console.log('Notification permission granted.');
11 | // TODO(developer): Retrieve a registration token for use with FCM.
12 | // ...
13 | } else {
14 | console.log('Unable to get permission to notify.');
15 | }
16 | });
17 | // [END messaging_request_permission_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/microsoft-oauth/auth_msft_provider_params_tenant.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/microsoft-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_msft_provider_params_tenant_modular]
8 | provider.setCustomParameters({
9 | // Optional "tenant" parameter in case you are using an Azure AD tenant.
10 | // eg. '8eaef023-2b34-4da1-9baa-8bc8c9d6a490' or 'contoso.onmicrosoft.com'
11 | // or "common" for tenant-independent tokens.
12 | // The default value is "common".
13 | tenant: 'TENANT_ID'
14 | });
15 | // [END auth_msft_provider_params_tenant_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/ecommerce.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_ecommerce_view_item_details_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | // Prepare ecommerce event params
11 | const params3 = {
12 | currency: 'USD',
13 | value: 9.99,
14 | items: [item_jeggings]
15 | };
16 |
17 | // Log event
18 | const analytics = getAnalytics();
19 | logEvent(analytics, 'view_item', params3);
20 | // [END analytics_ecommerce_view_item_details_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/link-multiple-accounts/auth_simple_link.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/link-multiple-accounts.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_simple_link_modular]
8 | import { getAuth, linkWithCredential } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | linkWithCredential(auth.currentUser, credential)
12 | .then((usercred) => {
13 | const user = usercred.user;
14 | console.log("Account linking success", user);
15 | }).catch((error) => {
16 | console.log("Account linking error", error);
17 | });
18 | // [END auth_simple_link_modular]
--------------------------------------------------------------------------------
/snippets/database-next/read-and-write/rtdb_read_once_get.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/read-and-write.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_read_once_get_modular]
8 | import { getDatabase, ref, child, get } from "firebase/database";
9 |
10 | const dbRef = ref(getDatabase());
11 | get(child(dbRef, `users/${userId}`)).then((snapshot) => {
12 | if (snapshot.exists()) {
13 | console.log(snapshot.val());
14 | } else {
15 | console.log("No data available");
16 | }
17 | }).catch((error) => {
18 | console.error(error);
19 | });
20 | // [END rtdb_read_once_get_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/listen_for_users.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START listen_for_users_modular]
8 | import { collection, where, query, onSnapshot } from "firebase/firestore";
9 |
10 | const q = query(collection(db, "users"), where("born", "<", 1900));
11 | const unsubscribe = onSnapshot(q, (snapshot) => {
12 | console.log("Current users born before 1900:");
13 | snapshot.forEach((userSnapshot) => {
14 | console.log(userSnapshot.data());
15 | });
16 | });
17 | // [END listen_for_users_modular]
--------------------------------------------------------------------------------
/auth/custom.js:
--------------------------------------------------------------------------------
1 | // These samples are intended for Web so this import would normally be
2 | // done in HTML however using modules here is more convenient for
3 | // ensuring sample correctness offline.
4 | import firebase from "firebase/app";
5 | import "firebase/auth";
6 |
7 | function signInCustom() {
8 | var token = "token123";
9 | // [START auth_sign_in_custom]
10 | firebase.auth().signInWithCustomToken(token)
11 | .then((userCredential) => {
12 | // Signed in
13 | var user = userCredential.user;
14 | // ...
15 | })
16 | .catch((error) => {
17 | var errorCode = error.code;
18 | var errorMessage = error.message;
19 | // ...
20 | });
21 | // [END auth_sign_in_custom]
22 | }
23 |
--------------------------------------------------------------------------------
/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/ecommerce.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_ecommerce_select_item_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | // Prepare ecommerce event params
11 | const params2 = {
12 | item_list_id: 'L001',
13 | item_list_name: 'Related products',
14 | items: [item_jeggings]
15 | };
16 |
17 | // Log event
18 | const analytics = getAnalytics();
19 | logEvent(analytics, 'select_item', params2);
20 | // [END analytics_ecommerce_select_item_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/custom/auth_sign_in_custom.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/custom.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_custom_modular]
8 | import { getAuth, signInWithCustomToken } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithCustomToken(auth, token)
12 | .then((userCredential) => {
13 | // Signed in
14 | const user = userCredential.user;
15 | // ...
16 | })
17 | .catch((error) => {
18 | const errorCode = error.code;
19 | const errorMessage = error.message;
20 | // ...
21 | });
22 | // [END auth_sign_in_custom_modular]
--------------------------------------------------------------------------------
/snippets/database-next/read-and-write/rtdb_social_completion_callback.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/read-and-write.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_social_completion_callback_modular]
8 | import { getDatabase, ref, set } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | set(ref(db, 'users/' + userId), {
12 | username: name,
13 | email: email,
14 | profile_picture : imageUrl
15 | })
16 | .then(() => {
17 | // Data saved successfully!
18 | })
19 | .catch((error) => {
20 | // The write failed...
21 | });
22 | // [END rtdb_social_completion_callback_modular]
--------------------------------------------------------------------------------
/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/read-and-write.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_write_new_user_completion_modular]
8 | import { getDatabase, ref, set } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | set(ref(db, 'users/' + userId), {
12 | username: name,
13 | email: email,
14 | profile_picture : imageUrl
15 | })
16 | .then(() => {
17 | // Data saved successfully!
18 | })
19 | .catch((error) => {
20 | // The write failed...
21 | });
22 | // [END rtdb_write_new_user_completion_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/firestore_query_subcollection.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START firestore_query_subcollection_modular]
8 | import { collection, getDocs } from "firebase/firestore";
9 | // Query a reference to a subcollection
10 | const querySnapshot = await getDocs(collection(db, "cities", "SF", "landmarks"));
11 | querySnapshot.forEach((doc) => {
12 | // doc.data() is never undefined for query doc snapshots
13 | console.log(doc.id, " => ", doc.data());
14 | });
15 | // [END firestore_query_subcollection_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/ecommerce.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_ecommerce_checkout_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | // Prepare ecommerce params
11 | const params7 = {
12 | currency: 'USD',
13 | value: 14.98, // Total Revenue
14 | coupon: 'SUMMER_FUN',
15 | items: [item_jeggings]
16 | };
17 |
18 | // Log event
19 | const analytics = getAnalytics();
20 | logEvent(analytics, 'begin_checkout', params7);
21 | // [END analytics_ecommerce_checkout_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/email/auth_signin_password.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/email.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_signin_password_modular]
8 | import { getAuth, signInWithEmailAndPassword } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithEmailAndPassword(auth, email, password)
12 | .then((userCredential) => {
13 | // Signed in
14 | const user = userCredential.user;
15 | // ...
16 | })
17 | .catch((error) => {
18 | const errorCode = error.code;
19 | const errorMessage = error.message;
20 | });
21 | // [END auth_signin_password_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/multi-tenancy/multitenant_signin_password.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/multi-tenancy.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START multitenant_signin_password_modular]
8 | import { signInWithEmailAndPassword } from "firebase/auth";
9 | auth.tenantId = 'TENANT_ID';
10 |
11 | signInWithEmailAndPassword(auth, email, password)
12 | .then((userCredential) => {
13 | // User is signed in.
14 | // userCredential.user.tenantId is 'TENANT_ID'.
15 | }).catch((error) => {
16 | // Handle / display error.
17 | // ...
18 | });
19 | // [END multitenant_signin_password_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/phone-auth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_phone_recaptcha_verifier_invisible_modular]
8 | import { getAuth, RecaptchaVerifier } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | window.recaptchaVerifier = new RecaptchaVerifier(auth, 'sign-in-button', {
12 | 'size': 'invisible',
13 | 'callback': (response) => {
14 | // reCAPTCHA solved, allow signInWithPhoneNumber.
15 | onSignInSubmit();
16 | }
17 | });
18 | // [END auth_phone_recaptcha_verifier_invisible_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/upload-files/storage_upload_bytes.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/upload-files.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_upload_bytes_modular]
8 | import { getStorage, ref, uploadBytes } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 | const storageRef = ref(storage, 'some-child');
12 |
13 | const bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21]);
14 | uploadBytes(storageRef, bytes).then((snapshot) => {
15 | console.log('Uploaded an array!');
16 | });
17 | // [END storage_upload_bytes_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/multi-tenancy/multitenant_signup_password.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/multi-tenancy.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START multitenant_signup_password_modular]
8 | import { createUserWithEmailAndPassword } from "firebase/auth";
9 | auth.tenantId = 'TENANT_ID';
10 |
11 | createUserWithEmailAndPassword(auth, email, password)
12 | .then((userCredential) => {
13 | // User is signed in.
14 | // userCredential.user.tenantId is 'TENANT_ID'.
15 | }).catch((error) => {
16 | // Handle / display error.
17 | // ...
18 | });
19 | // [END multitenant_signup_password_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-counters/get_count.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-counters.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START get_count_modular]
8 | async function getCount(ref) {
9 | import { collection, getDocs } from "firebase/firestore";
10 |
11 | // Sum the count of each shard in the subcollection
12 | const snapshot = await getDocs(collection(ref, 'shards'));
13 |
14 | let totalCount = 0;
15 | snapshot.forEach((doc) => {
16 | totalCount += doc.data().count;
17 | });
18 |
19 | return totalCount;
20 | }
21 | // [END get_count_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/get_custom_object.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START get_custom_object_modular]
8 | import { doc, getDoc} from "firebase/firestore";
9 |
10 | const ref = doc(db, "cities", "LA").withConverter(cityConverter);
11 | const docSnap = await getDoc(ref);
12 | if (docSnap.exists()) {
13 | // Convert to City object
14 | const city = docSnap.data();
15 | // Use a City instance method
16 | console.log(city.toString());
17 | } else {
18 | console.log("No such document!");
19 | }
20 | // [END get_custom_object_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/delete-files/storage_delete_file.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/delete-files.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_delete_file_modular]
8 | import { getStorage, ref, deleteObject } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 |
12 | // Create a reference to the file to delete
13 | const desertRef = ref(storage, 'images/desert.jpg');
14 |
15 | // Delete the file
16 | deleteObject(desertRef).then(() => {
17 | // File deleted successfully
18 | }).catch((error) => {
19 | // Uh-oh, an error occurred!
20 | });
21 | // [END storage_delete_file_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/index/auth_state_listener.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_state_listener_modular]
8 | import { getAuth, onAuthStateChanged } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | onAuthStateChanged(auth, (user) => {
12 | if (user) {
13 | // User is signed in, see docs for a list of available properties
14 | // https://firebase.google.com/docs/reference/js/auth.user
15 | const uid = user.uid;
16 | // ...
17 | } else {
18 | // User is signed out
19 | // ...
20 | }
21 | });
22 | // [END auth_state_listener_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/link-multiple-accounts.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_anonymous_link_modular]
8 | import { getAuth, linkWithCredential } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | linkWithCredential(auth.currentUser, credential)
12 | .then((usercred) => {
13 | const user = usercred.user;
14 | console.log("Anonymous account successfully upgraded", user);
15 | }).catch((error) => {
16 | console.log("Error upgrading anonymous account", error);
17 | });
18 | // [END auth_anonymous_link_modular]
--------------------------------------------------------------------------------
/snippets/database-next/lists-of-data/rtdb_social_listen_value.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/lists-of-data.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_social_listen_value_modular]
8 | import { getDatabase, ref, onValue } from "firebase/database";
9 |
10 | const db = getDatabase();
11 | const dbRef = ref(db, '/a/b/c');
12 |
13 | onValue(dbRef, (snapshot) => {
14 | snapshot.forEach((childSnapshot) => {
15 | const childKey = childSnapshot.key;
16 | const childData = childSnapshot.val();
17 | // ...
18 | });
19 | }, {
20 | onlyOnce: true
21 | });
22 | // [END rtdb_social_listen_value_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/listen_multiple.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START listen_multiple_modular]
8 | import { collection, query, where, onSnapshot } from "firebase/firestore";
9 |
10 | const q = query(collection(db, "cities"), where("state", "==", "CA"));
11 | const unsubscribe = onSnapshot(q, (querySnapshot) => {
12 | const cities = [];
13 | querySnapshot.forEach((doc) => {
14 | cities.push(doc.data().name);
15 | });
16 | console.log("Current cities in CA: ", cities.join(", "));
17 | });
18 | // [END listen_multiple_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/email/auth_signup_password.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/email.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_signup_password_modular]
8 | import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | createUserWithEmailAndPassword(auth, email, password)
12 | .then((userCredential) => {
13 | // Signed up
14 | const user = userCredential.user;
15 | // ...
16 | })
17 | .catch((error) => {
18 | const errorCode = error.code;
19 | const errorMessage = error.message;
20 | // ..
21 | });
22 | // [END auth_signup_password_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/link-multiple-accounts/auth_get_redirect_result.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/link-multiple-accounts.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_redirect_result_modular]
8 | import { getRedirectResult } from "firebase/auth";
9 | getRedirectResult(auth).then((result) => {
10 | const credential = GoogleAuthProvider.credentialFromResult(result);
11 | if (credential) {
12 | // Accounts successfully linked.
13 | const user = result.user;
14 | // ...
15 | }
16 | }).catch((error) => {
17 | // Handle Errors here.
18 | // ...
19 | });
20 | // [END auth_get_redirect_result_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/ecommerce.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_ecommerce_view_item_list_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | // Prepare ecommerce params
11 | const params1 = {
12 | item_list_id: 'L001',
13 | item_list_name: 'Related products',
14 | items: [item_jeggings, item_boots, item_socks]
15 | };
16 |
17 | // Log event
18 | const analytics = getAnalytics();
19 | logEvent(analytics, 'view_item_list', params1);
20 | // [END analytics_ecommerce_view_item_list_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/google-signin/auth_google_signin_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/google-signin.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_google_signin_credential_modular]
8 | signInWithCredential(auth, credential).catch((error) => {
9 | // Handle Errors here.
10 | const errorCode = error.code;
11 | const errorMessage = error.message;
12 | // The email of the user's account used.
13 | const email = error.customData.email;
14 | // The credential that was used.
15 | const credential = GoogleAuthProvider.credentialFromError(error);
16 | // ...
17 | });
18 | // [END auth_google_signin_credential_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-counters/increment_counter.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-counters.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START increment_counter_modular]
8 | function incrementCounter(db, ref, num_shards) {
9 | import { doc, updateDoc, increment } from "firebase/firestore";
10 |
11 | // Select a shard of the counter at random
12 | const shardId = Math.floor(Math.random() * num_shards).toString();
13 | const shardRef = doc(ref, 'shards', shardId);
14 |
15 | // Update count
16 | return updateDoc(shardRef, "count", increment(1));
17 | }
18 | // [END increment_counter_modular]
--------------------------------------------------------------------------------
/snippets/functions-next/callable/fb_functions_call_add_message.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./functions-next/callable.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START fb_functions_call_add_message_modular]
8 | import { getFunctions, httpsCallable } from "firebase/functions";
9 |
10 | const functions = getFunctions();
11 | const addMessage = httpsCallable(functions, 'addMessage');
12 | addMessage({ text: messageText })
13 | .then((result) => {
14 | // Read result of the Cloud Function.
15 | /** @type {any} */
16 | const data = result.data;
17 | const sanitizedMessage = data.text;
18 | });
19 | // [END fb_functions_call_add_message_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/ecommerce.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_ecommerce_payment_info_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | // Prepare ecommerce params
11 | const params9 = {
12 | currency: 'USD',
13 | value: 14.98, // Total Revenue
14 | coupon: 'SUMMER_FUN',
15 | payment_type: 'Visa',
16 | items: [item_jeggings]
17 | };
18 |
19 | // Log event
20 | const analytics = getAnalytics();
21 | logEvent(analytics, 'add_payment_info', params9);
22 | // [END analytics_ecommerce_payment_info_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/add_alan_turing.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START add_alan_turing_modular]
8 | // Add a second document with a generated ID.
9 | import { addDoc, collection } from "firebase/firestore";
10 |
11 | try {
12 | const docRef = await addDoc(collection(db, "users"), {
13 | first: "Alan",
14 | middle: "Mathison",
15 | last: "Turing",
16 | born: 1912
17 | });
18 |
19 | console.log("Document written with ID: ", docRef.id);
20 | } catch (e) {
21 | console.error("Error adding document: ", e);
22 | }
23 | // [END add_alan_turing_modular]
--------------------------------------------------------------------------------
/snippets/functions-next/emulator-suite/fb_functions_callable_call.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./functions-next/emulator-suite.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START fb_functions_callable_call_modular]
8 | import { getApp } from "firebase/app";
9 | import { getFunctions, httpsCallable } from "firebase/functions";
10 |
11 | const functions = getFunctions(getApp());
12 | const addMessage = httpsCallable(functions, 'addMessage');
13 |
14 | const result = await addMessage({ text: ''});
15 | /** @type {any} */
16 | const data = result.data;
17 | const sanitizedMessage = data.text;
18 | // ...
19 | // [END fb_functions_callable_call_modular]
--------------------------------------------------------------------------------
/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/ecommerce.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_ecommerce_shipping_info_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | // Prepare ecommerce params
11 | const params8 = {
12 | currency: 'USD',
13 | value: 14.98, // Total Revenue
14 | coupon: 'SUMMER_FUN',
15 | shipping_tier: 'Ground',
16 | items: [item_jeggings]
17 | };
18 |
19 | // Log event
20 | const analytics = getAnalytics();
21 | logEvent(analytics, 'add_shipping_info', params8);
22 | // [END analytics_ecommerce_shipping_info_modular]
--------------------------------------------------------------------------------
/snippets/perf-next/index/perf_add_custom_attributes.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./perf-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START perf_add_custom_attributes_modular]
8 | import { trace } from "firebase/performance";
9 |
10 | const t = trace(perf, "test_trace");
11 | t.putAttribute("experiment", "A");
12 |
13 | // Update scenario
14 | t.putAttribute("experiment", "B");
15 |
16 | // Reading scenario
17 | const experimentValue = t.getAttribute("experiment");
18 |
19 | // Delete scenario
20 | t.removeAttribute("experiment");
21 |
22 | // Read attributes
23 | const traceAttributes = t.getAttributes();
24 | // [END perf_add_custom_attributes_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/upload-files/storage_upload_metadata.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/upload-files.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_upload_metadata_modular]
8 | import { getStorage, ref, uploadBytes } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 | const storageRef = ref(storage, 'images/mountains.jpg');
12 |
13 | // Create file metadata including the content type
14 | /** @type {any} */
15 | const metadata = {
16 | contentType: 'image/jpeg',
17 | };
18 |
19 | // Upload the file and metadata
20 | const uploadTask = uploadBytes(storageRef, file, metadata);
21 | // [END storage_upload_metadata_modular]
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "snippets-web",
3 | "version": "1.0.0",
4 | "type": "module",
5 | "scripts": {
6 | "snippets": "rimraf snippets && node --loader ts-node/esm scripts/separate-snippets.ts",
7 | "lint": "git ls-files | grep -v 'snippets/' | grep '.js$' | xargs npx eslint",
8 | "format": "npm run lint -- --fix",
9 | "bootstrap": "find . -type f -name package.json -not -path '*/node_modules/*' -exec bash -c 'cd $(dirname {}) && npm install' \\;",
10 | "compile": "bash scripts/compile.sh"
11 | },
12 | "license": "Apache-2.0",
13 | "devDependencies": {
14 | "@eslint/js": "^9.38.0",
15 | "@types/node": "^24.9.1",
16 | "eslint": "^9.38.0",
17 | "rimraf": "^5.0.10",
18 | "ts-node": "^10.9.2",
19 | "typescript": "^5.9.0"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/SNIPPETS.md:
--------------------------------------------------------------------------------
1 | # Generated Snippets
2 |
3 | ## Overview
4 |
5 | The `snippets` directory contains snippets generated by the `separate-snippets` script.
6 | Snippets in this folder should **never** be updated directly instead please
7 | edit the source file (indicated by a comment at the top).
8 |
9 | ## Regenerating the Snippets
10 |
11 | Run `npm run snippets` from the root of this repository.
12 |
13 | ## Using the Separator
14 |
15 | For a file to be included in the separator script it must contain a comment like this:
16 |
17 | ```js
18 | // [SNIPPETS_SEPARATION enabled]
19 | ```
20 |
21 | By default separated snippets will have their name suffixed with `_modular`
22 | but you can override this with a commment:
23 |
24 | ```js
25 | // [SNIPPETS_SUFFIX _banana]
26 | ```
27 |
--------------------------------------------------------------------------------
/snippets/storage-next/create-reference/storage_navigate_ref_chain.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/create-reference.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_navigate_ref_chain_modular]
8 | import { getStorage, ref } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 | const spaceRef = ref(storage, 'images/space.jpg');
12 |
13 | // References can be chained together multiple times
14 | const earthRef = ref(spaceRef.parent, 'earth.jpg');
15 | // earthRef points to 'images/earth.jpg'
16 |
17 | // nullRef is null, since the parent of root is null
18 | const nullRef = spaceRef.root.parent;
19 | // [END storage_navigate_ref_chain_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/manage/auth_reauth_with_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/manage.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_reauth_with_credential_modular]
8 | import { getAuth, reauthenticateWithCredential } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | const user = auth.currentUser;
12 |
13 | // TODO(you): prompt the user to re-provide their sign-in credentials
14 | const credential = promptForCredentials();
15 |
16 | reauthenticateWithCredential(user, credential).then(() => {
17 | // User re-authenticated.
18 | }).catch((error) => {
19 | // An error ocurred
20 | // ...
21 | });
22 | // [END auth_reauth_with_credential_modular]
--------------------------------------------------------------------------------
/snippets/database-next/read-and-write/rtdb_social_single_value_read.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/read-and-write.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_social_single_value_read_modular]
8 | import { getDatabase, ref, onValue } from "firebase/database";
9 | import { getAuth } from "firebase/auth";
10 |
11 | const db = getDatabase();
12 | const auth = getAuth();
13 |
14 | const userId = auth.currentUser.uid;
15 | return onValue(ref(db, '/users/' + userId), (snapshot) => {
16 | const username = (snapshot.val() && snapshot.val().username) || 'Anonymous';
17 | // ...
18 | }, {
19 | onlyOnce: true
20 | });
21 | // [END rtdb_social_single_value_read_modular]
--------------------------------------------------------------------------------
/snippets/messaging-next/index/messaging_receive_message.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./messaging-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START messaging_receive_message_modular]
8 | // Handle incoming messages. Called when:
9 | // - a message is received while the app has focus
10 | // - the user clicks on an app notification created by a service worker
11 | // `messaging.onBackgroundMessage` handler.
12 | import { getMessaging, onMessage } from "firebase/messaging";
13 |
14 | const messaging = getMessaging();
15 | onMessage(messaging, (payload) => {
16 | console.log('Message received. ', payload);
17 | // ...
18 | });
19 | // [END messaging_receive_message_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/create-reference/storage_create_ref_child.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/create-reference.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_create_ref_child_modular]
8 | import { getStorage, ref } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 |
12 | // Create a child reference
13 | const imagesRef = ref(storage, 'images');
14 | // imagesRef now points to 'images'
15 |
16 | // Child references can also take paths delimited by '/'
17 | const spaceRef = ref(storage, 'images/space.jpg');
18 | // spaceRef now points to "images/space.jpg"
19 | // imagesRef still points to "images"
20 | // [END storage_create_ref_child_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/create-reference/storage_navigate_ref.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/create-reference.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_navigate_ref_modular]
8 | import { getStorage, ref } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 | const spaceRef = ref(storage, 'images/space.jpg');
12 |
13 | // Parent allows us to move to the parent of a reference
14 | const imagesRef = spaceRef.parent;
15 | // imagesRef now points to 'images'
16 |
17 | // Root allows us to move all the way back to the top of our bucket
18 | const rootRef = spaceRef.root;
19 | // rootRef now points to the root
20 | // [END storage_navigate_ref_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/upload-files/storage_manage_uploads.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/upload-files.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_manage_uploads_modular]
8 | import { getStorage, ref, uploadBytesResumable } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 | const storageRef = ref(storage, 'images/mountains.jpg');
12 |
13 | // Upload the file and metadata
14 | const uploadTask = uploadBytesResumable(storageRef, file);
15 |
16 | // Pause the upload
17 | uploadTask.pause();
18 |
19 | // Resume the upload
20 | uploadTask.resume();
21 |
22 | // Cancel the upload
23 | uploadTask.cancel();
24 | // [END storage_manage_uploads_modular]
--------------------------------------------------------------------------------
/snippets/database-next/read-and-write/rtdb_social_star_increment.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/read-and-write.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_social_star_increment_modular]
8 | function addStar(uid, key) {
9 | import { getDatabase, increment, ref, update } from "firebase/database";
10 | const dbRef = ref(getDatabase());
11 |
12 | const updates = {};
13 | updates[`posts/${key}/stars/${uid}`] = true;
14 | updates[`posts/${key}/starCount`] = increment(1);
15 | updates[`user-posts/${key}/stars/${uid}`] = true;
16 | updates[`user-posts/${key}/starCount`] = increment(1);
17 | update(dbRef, updates);
18 | }
19 | // [END rtdb_social_star_increment_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/link-multiple-accounts.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_link_with_popup_modular]
8 | import { getAuth, linkWithPopup, GoogleAuthProvider } from "firebase/auth";
9 | const provider = new GoogleAuthProvider();
10 |
11 | const auth = getAuth();
12 | linkWithPopup(auth.currentUser, provider).then((result) => {
13 | // Accounts successfully linked.
14 | const credential = GoogleAuthProvider.credentialFromResult(result);
15 | const user = result.user;
16 | // ...
17 | }).catch((error) => {
18 | // Handle Errors here.
19 | // ...
20 | });
21 | // [END auth_link_with_popup_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/multi-tenancy/multitenant_create_custom_token.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/multi-tenancy.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START multitenant_create_custom_token_modular]
8 | // Ensure you're using a tenant-aware auth instance
9 | const tenantManager = admin.auth().tenantManager();
10 | const tenantAuth = tenantManager.authForTenant('TENANT_ID1');
11 |
12 | // Create a custom token in the usual manner
13 | tenantAuth.createCustomToken(uid)
14 | .then((customToken) => {
15 | // Send token back to client
16 | })
17 | .catch((error) => {
18 | console.log('Error creating custom token:', error);
19 | });
20 | // [END multitenant_create_custom_token_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/update_document_array.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START update_document_array_modular]
8 | import { doc, updateDoc, arrayUnion, arrayRemove } from "firebase/firestore";
9 |
10 | const washingtonRef = doc(db, "cities", "DC");
11 |
12 | // Atomically add a new region to the "regions" array field.
13 | await updateDoc(washingtonRef, {
14 | regions: arrayUnion("greater_virginia")
15 | });
16 |
17 | // Atomically remove a region from the "regions" array field.
18 | await updateDoc(washingtonRef, {
19 | regions: arrayRemove("east_coast")
20 | });
21 | // [END update_document_array_modular]
--------------------------------------------------------------------------------
/auth-next/emulator-suite.js:
--------------------------------------------------------------------------------
1 | // [SNIPPET_REGISTRY disabled]
2 | // [SNIPPETS_SEPARATION enabled]
3 |
4 | function emulatorConnect() {
5 | // [START auth_emulator_connect]
6 | const { getAuth, connectAuthEmulator } = require("firebase/auth");
7 |
8 | const auth = getAuth();
9 | connectAuthEmulator(auth, "http://127.0.0.1:9099");
10 | // [END auth_emulator_connect]
11 | }
12 |
13 | function emulatorGoogleCredential() {
14 | // [START auth_emulator_google_credential]
15 | const { getAuth, signInWithCredential, GoogleAuthProvider } = require("firebase/auth");
16 |
17 | const auth = getAuth();
18 | signInWithCredential(auth, GoogleAuthProvider.credential(
19 | '{"sub": "abc123", "email": "foo@example.com", "email_verified": true}'
20 | ));
21 | // [END auth_emulator_google_credential]
22 | }
23 |
24 |
25 |
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/start_multiple_orderby.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START start_multiple_orderby_modular]
8 | // Will return all Springfields
9 | import { collection, query, orderBy, startAt } from "firebase/firestore";
10 | const q1 = query(collection(db, "cities"),
11 | orderBy("name"),
12 | orderBy("state"),
13 | startAt("Springfield"));
14 |
15 | // Will return "Springfield, Missouri" and "Springfield, Wisconsin"
16 | const q2 = query(collection(db, "cities"),
17 | orderBy("name"),
18 | orderBy("state"),
19 | startAt("Springfield", "Missouri"));
20 | // [END start_multiple_orderby_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/update_document_nested.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START update_document_nested_modular]
8 | import { doc, setDoc, updateDoc } from "firebase/firestore";
9 |
10 | // Create an initial document to update.
11 | const frankDocRef = doc(db, "users", "frank");
12 | await setDoc(frankDocRef, {
13 | name: "Frank",
14 | favorites: { food: "Pizza", color: "Blue", subject: "recess" },
15 | age: 12
16 | });
17 |
18 | // To update age and favorite color:
19 | await updateDoc(frankDocRef, {
20 | "age": 13,
21 | "favorites.color": "Red"
22 | });
23 | // [END update_document_nested_modular]
--------------------------------------------------------------------------------
/database-next/emulator-suite.js:
--------------------------------------------------------------------------------
1 | // [SNIPPET_REGISTRY disabled]
2 | // [SNIPPETS_SEPARATION enabled]
3 |
4 | function onDocumentReady() {
5 | // [START rtdb_emulator_connect]
6 | const { getDatabase, connectDatabaseEmulator } = require("firebase/database");
7 |
8 | const db = getDatabase();
9 | if (location.hostname === "localhost") {
10 | // Point to the RTDB emulator running on localhost.
11 | connectDatabaseEmulator(db, "127.0.0.1", 9000);
12 | }
13 | // [END rtdb_emulator_connect]
14 | }
15 |
16 | function flushRealtimeDatabase() {
17 | // [START rtdb_emulator_flush]
18 | const { getDatabase, ref, set } = require("firebase/database");
19 |
20 | // With a database Reference, write null to clear the database.
21 | const db = getDatabase();
22 | set(ref(db), null);
23 | // [END rtdb_emulator_flush]
24 | }
25 |
--------------------------------------------------------------------------------
/database/emulator-suite.js:
--------------------------------------------------------------------------------
1 |
2 | // These samples are intended for Web so this import would normally be
3 | // done in HTML however using modules here is more convenient for
4 | // ensuring sample correctness offline.
5 | import firebase from "firebase/app";
6 | import "firebase/database";
7 |
8 | function onDocumentReady() {
9 | // [START rtdb_emulator_connect]
10 | var db = firebase.database();
11 | if (location.hostname === "localhost") {
12 | // Point to the RTDB emulator running on localhost.
13 | db.useEmulator("127.0.0.1", 9000);
14 | }
15 | // [END rtdb_emulator_connect]
16 | }
17 |
18 | function flushRealtimeDatabase() {
19 | // [START rtdb_emulator_flush]
20 | // With a database Reference, write null to clear the database.
21 | firebase.database().ref().set(null);
22 | // [END rtdb_emulator_flush]
23 | }
24 |
--------------------------------------------------------------------------------
/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./analytics-next/ecommerce.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START analytics_ecommerce_purchase_modular]
8 | import { getAnalytics, logEvent } from "firebase/analytics";
9 |
10 | // Prepare ecommerce bundle
11 | const params10 = {
12 | transaction_id: 'T12345',
13 | affiliation: 'Google Store',
14 | currency: 'USD',
15 | value: 14.98, // Total Revenue
16 | tax: 2.85,
17 | shipping: 5.34,
18 | coupon: 'SUMMER_FUN',
19 | items: [item_jeggings]
20 | };
21 |
22 | // Log event
23 | const analytics = getAnalytics();
24 | logEvent(analytics, 'purchase', params10);
25 | // [END analytics_ecommerce_purchase_modular]
--------------------------------------------------------------------------------
/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./appcheck-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START appcheck_initialize_custom_provider_modular]
8 | import { initializeApp } from "firebase/app";
9 | import { initializeAppCheck } from "firebase/app-check";
10 |
11 | const app = initializeApp({
12 | // Your firebase configuration object
13 | });
14 |
15 | const appCheck = initializeAppCheck(app, {
16 | provider: appCheckCustomProvider,
17 |
18 | // Optional argument. If true, the SDK automatically refreshes App Check
19 | // tokens as needed.
20 | isTokenAutoRefreshEnabled: true
21 | });
22 | // [END appcheck_initialize_custom_provider_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/service-worker-sessions.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_svc_sign_in_email_modular]
8 | import { getAuth, signInWithEmailAndPassword } from "firebase/auth";
9 |
10 | // Sign in screen.
11 | const auth = getAuth();
12 | signInWithEmailAndPassword(auth, email, password)
13 | .then((result) => {
14 | // Redirect to profile page after sign-in. The service worker will detect
15 | // this and append the ID token to the header.
16 | window.location.assign('/profile');
17 | })
18 | .catch((error) => {
19 | // Error occurred.
20 | });
21 | // [END auth_svc_sign_in_email_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/file-metadata/storage_get_metadata.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/file-metadata.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_get_metadata_modular]
8 | import { getStorage, ref, getMetadata } from "firebase/storage";
9 |
10 | // Create a reference to the file whose metadata we want to retrieve
11 | const storage = getStorage();
12 | const forestRef = ref(storage, 'images/forest.jpg');
13 |
14 | // Get metadata properties
15 | getMetadata(forestRef)
16 | .then((metadata) => {
17 | // Metadata now contains the metadata for 'images/forest.jpg'
18 | })
19 | .catch((error) => {
20 | // Uh-oh, an error occurred!
21 | });
22 | // [END storage_get_metadata_modular]
--------------------------------------------------------------------------------
/database/sharding.js:
--------------------------------------------------------------------------------
1 | // These samples are intended for Web so this import would normally be
2 | // done in HTML however using modules here is more convenient for
3 | // ensuring sample correctness offline.
4 | import firebase from "firebase/app";
5 | import "firebase/database";
6 |
7 | function multipleInstances() {
8 | // [START rtdb_multiple_instances]
9 | const app1 = firebase.initializeApp({
10 | databaseURL: "https://testapp-1234-1.firebaseio.com"
11 | });
12 |
13 | const app2 = firebase.initializeApp({
14 | databaseURL: "https://testapp-1234-2.firebaseio.com"
15 | }, 'app2');
16 |
17 | // Get the default database instance for an app1
18 | var database1 = firebase.database();
19 |
20 | // Get a database instance for app2
21 | var database2 = firebase.database(app2);
22 | // [END rtdb_multiple_instances]
23 | }
24 |
--------------------------------------------------------------------------------
/snippets/auth-next/custom-dependencies/auth_get_auth_equivalent.js:
--------------------------------------------------------------------------------
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]
--------------------------------------------------------------------------------
/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/phone-auth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_phone_recaptcha_verifier_visible_modular]
8 | import { getAuth, RecaptchaVerifier } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | window.recaptchaVerifier = new RecaptchaVerifier(auth, 'recaptcha-container', {
12 | 'size': 'normal',
13 | 'callback': (response) => {
14 | // reCAPTCHA solved, allow signInWithPhoneNumber.
15 | // ...
16 | },
17 | 'expired-callback': () => {
18 | // Response expired. Ask user to solve reCAPTCHA again.
19 | // ...
20 | }
21 | });
22 | // [END auth_phone_recaptcha_verifier_visible_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/data_types.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START data_types_modular]
8 | import { doc, setDoc, Timestamp } from "firebase/firestore";
9 |
10 | const docData = {
11 | stringExample: "Hello world!",
12 | booleanExample: true,
13 | numberExample: 3.14159265,
14 | dateExample: Timestamp.fromDate(new Date("December 10, 1815")),
15 | arrayExample: [5, true, "hello"],
16 | nullExample: null,
17 | objectExample: {
18 | a: 5,
19 | b: {
20 | nested: "foo"
21 | }
22 | }
23 | };
24 | await setDoc(doc(db, "data", "one"), docData);
25 | // [END data_types_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/multi-tenancy/multitenant_switch_tenant_multiinstance.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/multi-tenancy.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START multitenant_switch_tenant_multiinstance_modular]
8 | // Multiple Auth instances
9 | import { initializeApp } from "firebase/app";
10 | import { getAuth } from "firebase/auth";
11 | const firebaseApp1 = initializeApp(firebaseConfig1, 'app1_for_tenantId1');
12 | const firebaseApp2 = initializeApp(firebaseConfig2, 'app2_for_tenantId2');
13 |
14 | const auth1 = getAuth(firebaseApp1);
15 | const auth2 = getAuth(firebaseApp2);
16 |
17 | auth1.tenantId = "TENANT_ID1";
18 | auth2.tenantId = "TENANT_ID2";
19 | // [END multitenant_switch_tenant_multiinstance_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/manage/auth_get_user_profile_provider.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/manage.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_user_profile_provider_modular]
8 | import { getAuth } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | const user = auth.currentUser;
12 |
13 | if (user !== null) {
14 | user.providerData.forEach((profile) => {
15 | console.log("Sign-in provider: " + profile.providerId);
16 | console.log(" Provider-specific UID: " + profile.uid);
17 | console.log(" Name: " + profile.displayName);
18 | console.log(" Email: " + profile.email);
19 | console.log(" Photo URL: " + profile.photoURL);
20 | });
21 | }
22 | // [END auth_get_user_profile_provider_modular]
--------------------------------------------------------------------------------
/snippets/database-next/sharding/rtdb_multiple_instances.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./database-next/sharding.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START rtdb_multiple_instances_modular]
8 | import { initializeApp } from "firebase/app";
9 | import { getDatabase } from "firebase/database";
10 |
11 | const app1 = initializeApp({
12 | databaseURL: "https://testapp-1234-1.firebaseio.com"
13 | });
14 |
15 | const app2 = initializeApp({
16 | databaseURL: "https://testapp-1234-2.firebaseio.com"
17 | }, 'app2');
18 |
19 | // Get the default database instance for an app1
20 | const database1 = getDatabase(app1);
21 |
22 | // Get a database instance for app2
23 | const database2 = getDatabase(app2);
24 | // [END rtdb_multiple_instances_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-geoqueries/fs_geo_add_hash.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-geoqueries.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START fs_geo_add_hash_modular]
8 | import { doc, updateDoc } from 'firebase/firestore';
9 |
10 | // Compute the GeoHash for a lat/lng point
11 | const lat = 51.5074;
12 | const lng = 0.1278;
13 | const hash = geofire.geohashForLocation([lat, lng]);
14 |
15 | // Add the hash and the lat/lng to the document. We will use the hash
16 | // for queries and the lat/lng for distance comparisons.
17 | const londonRef = doc(db, 'cities', 'LON');
18 | await updateDoc(londonRef, {
19 | geohash: hash,
20 | lat: lat,
21 | lng: lng
22 | });
23 | // [END fs_geo_add_hash_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/index/auth_signin_credential.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_signin_credential_modular]
8 | import { getAuth, signInWithCredential } from "firebase/auth";
9 |
10 | // Sign in with the credential from the user.
11 | const auth = getAuth();
12 | signInWithCredential(auth, credential)
13 | .then((result) => {
14 | // Signed in
15 | // ...
16 | })
17 | .catch((error) => {
18 | // Handle Errors here.
19 | const errorCode = error.code;
20 | const errorMessage = error.message;
21 | // The email of the user's account used.
22 | const email = error.customData.email;
23 | // ...
24 | });
25 | // [END auth_signin_credential_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/transaction.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START transaction_modular]
8 | import { runTransaction } from "firebase/firestore";
9 |
10 | try {
11 | await runTransaction(db, async (transaction) => {
12 | const sfDoc = await transaction.get(sfDocRef);
13 | if (!sfDoc.exists()) {
14 | throw "Document does not exist!";
15 | }
16 |
17 | const newPopulation = sfDoc.data().population + 1;
18 | transaction.update(sfDocRef, { population: newPopulation });
19 | });
20 | console.log("Transaction successfully committed!");
21 | } catch (e) {
22 | console.log("Transaction failed: ", e);
23 | }
24 | // [END transaction_modular]
--------------------------------------------------------------------------------
/firestore/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mocha Tests
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/get_document_options.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START get_document_options_modular]
8 | import { doc, getDocFromCache } from "firebase/firestore";
9 |
10 | const docRef = doc(db, "cities", "SF");
11 |
12 | // Get a document, forcing the SDK to fetch from the offline cache.
13 | try {
14 | const doc = await getDocFromCache(docRef);
15 |
16 | // Document was found in the cache. If no cached document exists,
17 | // an error will be returned to the 'catch' block below.
18 | console.log("Cached document data:", doc.data());
19 | } catch (e) {
20 | console.log("Error getting cached document:", e);
21 | }
22 | // [END get_document_options_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/write_batch.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START write_batch_modular]
8 | import { writeBatch, doc } from "firebase/firestore";
9 |
10 | // Get a new write batch
11 | const batch = writeBatch(db);
12 |
13 | // Set the value of 'NYC'
14 | const nycRef = doc(db, "cities", "NYC");
15 | batch.set(nycRef, {name: "New York City"});
16 |
17 | // Update the population of 'SF'
18 | const sfRef = doc(db, "cities", "SF");
19 | batch.update(sfRef, {"population": 1000000});
20 |
21 | // Delete the city 'LA'
22 | const laRef = doc(db, "cities", "LA");
23 | batch.delete(laRef);
24 |
25 | // Commit the batch
26 | await batch.commit();
27 | // [END write_batch_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/create-reference/storage_ref_properties.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/create-reference.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_ref_properties_modular]
8 | import { getStorage, ref } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 | const spaceRef = ref(storage, 'images/space.jpg');
12 |
13 | // Reference's path is: 'images/space.jpg'
14 | // This is analogous to a file path on disk
15 | spaceRef.fullPath;
16 |
17 | // Reference's name is the last segment of the full path: 'space.jpg'
18 | // This is analogous to the file name
19 | spaceRef.name;
20 |
21 | // Reference's bucket is the name of the storage bucket where files are stored
22 | spaceRef.bucket;
23 | // [END storage_ref_properties_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/file-metadata/storage_delete_metadata.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/file-metadata.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_delete_metadata_modular]
8 | import { getStorage, ref, updateMetadata } from "firebase/storage";
9 |
10 | const storage = getStorage();
11 | const forestRef = ref(storage, 'images/forest.jpg');
12 |
13 | // Create file metadata with property to delete
14 | const deleteMetadata = {
15 | contentType: null
16 | };
17 |
18 | // Delete the metadata property
19 | updateMetadata(forestRef, deleteMetadata)
20 | .then((metadata) => {
21 | // metadata.contentType should be null
22 | }).catch((error) => {
23 | // Uh-oh, an error occurred!
24 | });
25 | // [END storage_delete_metadata_modular]
--------------------------------------------------------------------------------
/snippets/perf-next/index/perf_add_custom_metrics.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./perf-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START perf_add_custom_metrics_modular]
8 | import { trace } from "firebase/performance";
9 |
10 | async function getInventory(inventoryIds) {
11 | const t = trace(perf, "inventoryRetrieval");
12 |
13 | // Tracks the number of IDs fetched (the metric could help you to optimize in the future)
14 | t.incrementMetric("numberOfIds", inventoryIds.length);
15 |
16 | // Measures the time it takes to request inventory based on the amount of inventory
17 | t.start();
18 | const inventoryData = await retrieveInventory(inventoryIds);
19 | t.stop();
20 |
21 | return inventoryData;
22 | }
23 | // [END perf_add_custom_metrics_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/custom-dependencies/auth_sign_in_redirect_manual_deps.js:
--------------------------------------------------------------------------------
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]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-firestore/use_from_cache.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.firestore.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START use_from_cache_modular]
8 | import { collection, onSnapshot, where, query } from "firebase/firestore";
9 |
10 | const q = query(collection(db, "cities"), where("state", "==", "CA"));
11 | onSnapshot(q, { includeMetadataChanges: true }, (snapshot) => {
12 | snapshot.docChanges().forEach((change) => {
13 | if (change.type === "added") {
14 | console.log("New city: ", change.doc.data());
15 | }
16 |
17 | const source = snapshot.metadata.fromCache ? "local cache" : "server";
18 | console.log("Data came from " + source);
19 | });
20 | });
21 | // [END use_from_cache_modular]
--------------------------------------------------------------------------------
/snippets/firestore-next/test-solution-counters/create_counter.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./firestore-next/test.solution-counters.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START create_counter_modular]
8 | function createCounter(ref, num_shards) {
9 | import { doc, writeBatch } from "firebase/firestore";
10 |
11 | const batch = writeBatch(db);
12 |
13 | // Initialize the counter document
14 | batch.set(ref, { num_shards: num_shards });
15 |
16 | // Initialize each shard with count=0
17 | for (let i = 0; i < num_shards; i++) {
18 | const shardRef = doc(ref, 'shards', i.toString());
19 | batch.set(shardRef, { count: 0 });
20 | }
21 |
22 | // Commit the write batch
23 | return batch.commit();
24 | }
25 | // [END create_counter_modular]
--------------------------------------------------------------------------------
/firebaseserverapp-next/firebaseserverapp.js:
--------------------------------------------------------------------------------
1 | // @ts-nocheck
2 | // [START serverapp_auth]
3 | import { initializeServerApp } from 'firebase/app';
4 | import { getAuth } from 'firebase/auth';
5 | import { headers } from 'next/headers';
6 | import { redirect } from 'next/navigation';
7 |
8 | export default function MyServerComponent() {
9 |
10 | // Get relevant request headers (in Next.JS)
11 | const authIdToken = headers().get('Authorization')?.split('Bearer ')[1];
12 |
13 | // Initialize the FirebaseServerApp instance.
14 | const serverApp = initializeServerApp(firebaseConfig, { authIdToken });
15 |
16 | // Initialize Firebase Authentication using the FirebaseServerApp instance.
17 | const auth = getAuth(serverApp);
18 |
19 | if (auth.currentUser) {
20 | redirect('/profile');
21 | }
22 |
23 | // ...
24 | }
25 | // [END serverapp_auth]
26 |
27 | const firebaseConfig = {};
28 |
--------------------------------------------------------------------------------
/snippets/auth-next/google-signin/auth_google_checksameuser.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/google-signin.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_google_checksameuser_modular]
8 | import { GoogleAuthProvider } from "firebase/auth";
9 |
10 | function isUserEqual(googleUser, firebaseUser) {
11 | if (firebaseUser) {
12 | const providerData = firebaseUser.providerData;
13 | for (let i = 0; i < providerData.length; i++) {
14 | if (providerData[i].providerId === GoogleAuthProvider.PROVIDER_ID &&
15 | providerData[i].uid === googleUser.getBasicProfile().getId()) {
16 | // We don't need to reauth the Firebase connection.
17 | return true;
18 | }
19 | }
20 | }
21 | return false;
22 | }
23 | // [END auth_google_checksameuser_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/facebook/auth_facebook_checksameuser.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/facebook.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_facebook_checksameuser_modular]
8 | import { FacebookAuthProvider } from "firebase/auth";
9 |
10 | function isUserEqual(facebookAuthResponse, firebaseUser) {
11 | if (firebaseUser) {
12 | const providerData = firebaseUser.providerData;
13 | for (let i = 0; i < providerData.length; i++) {
14 | if (providerData[i].providerId === FacebookAuthProvider.PROVIDER_ID &&
15 | providerData[i].uid === facebookAuthResponse.userID) {
16 | // We don't need to re-auth the Firebase connection.
17 | return true;
18 | }
19 | }
20 | }
21 | return false;
22 | }
23 | // [END auth_facebook_checksameuser_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/microsoft-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_msft_signin_popup_modular]
8 | import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithPopup(auth, provider)
12 | .then((result) => {
13 | // User is signed in.
14 | // IdP data available in result.additionalUserInfo.profile.
15 |
16 | // Get the OAuth access token and ID Token
17 | const credential = OAuthProvider.credentialFromResult(result);
18 | const accessToken = credential.accessToken;
19 | const idToken = credential.idToken;
20 | })
21 | .catch((error) => {
22 | // Handle error.
23 | });
24 | // [END auth_msft_signin_popup_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/multi-tenancy/multitenant_send_emaillink.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/multi-tenancy.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START multitenant_send_emaillink_modular]
8 | import { sendSignInLinkToEmail } from "firebase/auth";
9 | // Switch to TENANT_ID1
10 | auth.tenantId = 'TENANT_ID1';
11 |
12 | sendSignInLinkToEmail(auth, email, actionCodeSettings)
13 | .then(() => {
14 | // The link was successfully sent. Inform the user.
15 | // Save the email locally so you don't need to ask the user for it again
16 | // if they open the link on the same device.
17 | window.localStorage.setItem('emailForSignIn', email);
18 | })
19 | .catch((error) => {
20 | // Handle / display error.
21 | // ...
22 | });
23 | // [END multitenant_send_emaillink_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/multi-tenancy/multitenant_signin_saml_popup.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/multi-tenancy.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START multitenant_signin_saml_popup_modular]
8 | import { signInWithPopup } from "firebase/auth";
9 | // Switch to TENANT_ID1.
10 | auth.tenantId = 'TENANT_ID1';
11 |
12 | // Sign-in with popup.
13 | signInWithPopup(auth, provider)
14 | .then((userCredential) => {
15 | // User is signed in.
16 | const user = userCredential.user;
17 | // user.tenantId is set to 'TENANT_ID1'.
18 | // Provider data available from the result.user.getIdToken()
19 | // or from result.user.providerData
20 | })
21 | .catch((error) => {
22 | // Handle / display error.
23 | // ...
24 | });
25 | // [END multitenant_signin_saml_popup_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/yahoo-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_yahoo_signin_popup_modular]
8 | import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | signInWithPopup(auth, provider)
12 | .then((result) => {
13 | // IdP data available in result.additionalUserInfo.profile
14 | // ...
15 |
16 | // Yahoo OAuth access token and ID token can be retrieved by calling:
17 | const credential = OAuthProvider.credentialFromResult(result);
18 | const accessToken = credential.accessToken;
19 | const idToken = credential.idToken;
20 | })
21 | .catch((error) => {
22 | // Handle error.
23 | });
24 | // [END auth_yahoo_signin_popup_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/upload-files/storage_upload_ref.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/upload-files.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_upload_ref_modular]
8 | import { getStorage, ref } from "firebase/storage";
9 |
10 | // Create a root reference
11 | const storage = getStorage();
12 |
13 | // Create a reference to 'mountains.jpg'
14 | const mountainsRef = ref(storage, 'mountains.jpg');
15 |
16 | // Create a reference to 'images/mountains.jpg'
17 | const mountainImagesRef = ref(storage, 'images/mountains.jpg');
18 |
19 | // While the file names are the same, the references point to different files
20 | mountainsRef.name === mountainImagesRef.name; // true
21 | mountainsRef.fullPath === mountainImagesRef.fullPath; // false
22 | // [END storage_upload_ref_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/manage/auth_get_user_profile.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/manage.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_user_profile_modular]
8 | import { getAuth } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | const user = auth.currentUser;
12 | if (user !== null) {
13 | // The user object has basic properties such as display name, email, etc.
14 | const displayName = user.displayName;
15 | const email = user.email;
16 | const photoURL = user.photoURL;
17 | const emailVerified = user.emailVerified;
18 |
19 | // The user's ID, unique to the Firebase project. Do NOT use
20 | // this value to authenticate with your backend server, if
21 | // you have one. Use User.getToken() instead.
22 | const uid = user.uid;
23 | }
24 | // [END auth_get_user_profile_modular]
--------------------------------------------------------------------------------
/snippets/storage-next/index/storage_initialize.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./storage-next/index.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START storage_initialize_modular]
8 | import { initializeApp } from "firebase/app";
9 | import { getStorage } from "firebase/storage";
10 |
11 | // Set the configuration for your app
12 | // TODO: Replace with your app's config object
13 | const firebaseConfig = {
14 | apiKey: '',
15 | authDomain: '',
16 | databaseURL: '',
17 | storageBucket: ''
18 | };
19 | const firebaseApp = initializeApp(firebaseConfig);
20 |
21 | // Get a reference to the storage service, which is used to create references in your storage bucket
22 | const storage = getStorage(firebaseApp);
23 | // [END storage_initialize_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/email-link-auth/auth_email_link_send.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/email-link-auth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_email_link_send_modular]
8 | import { getAuth, sendSignInLinkToEmail } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | sendSignInLinkToEmail(auth, email, actionCodeSettings)
12 | .then(() => {
13 | // The link was successfully sent. Inform the user.
14 | // Save the email locally so you don't need to ask the user for it again
15 | // if they open the link on the same device.
16 | window.localStorage.setItem('emailForSignIn', email);
17 | // ...
18 | })
19 | .catch((error) => {
20 | const errorCode = error.code;
21 | const errorMessage = error.message;
22 | // ...
23 | });
24 | // [END auth_email_link_send_modular]
--------------------------------------------------------------------------------
/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js:
--------------------------------------------------------------------------------
1 | // This snippet file was generated by processing the source file:
2 | // ./auth-next/microsoft-oauth.js
3 | //
4 | // To update the snippets in this file, edit the source and then run
5 | // 'npm run snippets'.
6 |
7 | // [START auth_msft_signin_redirect_result_modular]
8 | import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth";
9 |
10 | const auth = getAuth();
11 | getRedirectResult(auth)
12 | .then((result) => {
13 | // User is signed in.
14 | // IdP data available in result.additionalUserInfo.profile.
15 |
16 | // Get the OAuth access token and ID Token
17 | const credential = OAuthProvider.credentialFromResult(result);
18 | const accessToken = credential.accessToken;
19 | const idToken = credential.idToken;
20 | })
21 | .catch((error) => {
22 | // Handle error.
23 | });
24 | // [END auth_msft_signin_redirect_result_modular]
--------------------------------------------------------------------------------