Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Creazione di una pagina di accesso per più tenant
Questo documento mostra come creare una pagina di accesso specifica per il tenant per Identity Platform utilizzando FirebaseUI, una raccolta di componenti UI predefiniti e open source, e l'SDK client.
Il codice di esempio che mostra i passaggi descritti in questo tutorial è disponibile su GitHub.
Creazione di un'interfaccia utente per la selezione del tenant
FirebaseUI gestisce solo i flussi di accesso. Dovrai creare la tua interfaccia utente per consentire agli utenti di selezionare un tenant con cui accedere. I passaggi riportati di seguito mostrano come
creare una semplice pagina di selezione del tenant con due pulsanti.
Crea due elementi di selezione del tenant.
<div id="tenant-selection-buttons">
<button id="tenant1-select-button" data-val="tenantId1">Display name of Tenant 1</button>
<button id="tenant2-select-button" data-val="tenantId2">Display name of Tenant 2</button>
</div>
Aggiungi gestori dei clic per la selezione del tenant per visualizzare il componente di accesso con FirebaseUI. Tieni presente che prima di eseguire il rendering del componente dell'interfaccia utente, devi impostare l'ID tenant nell'istanza Auth.
Avvia l'app. Viene visualizzata una schermata di accesso con due pulsanti tenant.
Sebbene questo esempio utilizzi due semplici pulsanti e una singola pagina, sono possibili molti diversiflussi UX. Ad esempio, potresti chiedere agli utenti di inserire il proprio indirizzo email su una pagina, quindi presentare una schermata di selezione dell'account cliente. Puoi anche ospitare pagine di accesso separate per ogni tenant. In questo caso, devi analizzare l'ID tenant dall'URL e impostarlo sull'oggetto Auth.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eThis document provides a guide on creating a tenant-specific sign-in page for Identity Platform using FirebaseUI and the Client SDK.\u003c/p\u003e\n"],["\u003cp\u003eYou must first enable multi-tenancy and configure identity providers for each tenant before implementing the sign-in page.\u003c/p\u003e\n"],["\u003cp\u003eFirebaseUI is used for sign-in flows, but the UI for tenant selection, such as buttons, must be custom-built.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves creating tenant selection elements, a FirebaseUI container, tenant-specific configurations, and click handlers to render the appropriate sign-in component.\u003c/p\u003e\n"],["\u003cp\u003eMultiple UX flows are possible, such as separate login pages for each tenant, where the tenant ID can be parsed from the URL.\u003c/p\u003e\n"]]],[],null,["# Creating a sign-in page for multiple tenants\n============================================\n\nThis document shows you how to build a tenant-specific sign-in page for\nIdentity Platform using\n[FirebaseUI](https://github.com/firebase/firebaseui-web), a\ncollection of open-source, pre-built UI components, and the\n[Client SDK](https://github.com/firebase/firebase-js-sdk).\n\nSample code demonstrating the steps covered in this tutorial is available\non [GitHub](https://github.com/firebase/quickstart-js/blob/master/auth/multi-tenant-ui.html).\n\nBefore you begin\n----------------\n\n1. [Enable multi-tenancy and create at least two tenants](/identity-platform/docs/multi-tenancy-quickstart).\n2. [Configure identity providers for each tenant](/identity-platform/docs/quickstart-cicp#add-provider).\n\nGetting the components\n----------------------\n\nYou can fetch the UI script, Client SDK, and CSS files directly\nfrom the CDN by adding them to the `\u003chead\u003e` element of your page: \n\n \u003cscript src=\"https://www.gstatic.com/firebasejs/x.x.x/firebase-app.js\"\u003e\u003c/script\u003e\n \u003cscript src=\"https://www.gstatic.com/firebasejs/x.x.x/firebase-auth.js\"\u003e\u003c/script\u003e\n \u003cscript src=\"https://cdn.firebase.com/libs/firebaseui/x.x.x/firebaseui.js\"\u003e\u003c/script\u003e\n \u003clink rel=\"stylesheet\" href=\"https://cdn.firebase.com/libs/firebaseui/x.x.x/firebaseui.css\" /\u003e\n\nAlternatively, you can install the modules using `npm`, and then reference them\nas ES6 imports: \n\n npm install firebase --save && \\\n npm install firebaseui --save\n\n // Import Firebase JS SDK.\n import * as firebase from \"firebase/app\";\n import \"firebase/auth\";\n import * as firebaseui from 'firebaseui'\n\n### Building a tenant selection UI\n\nFirebaseUI only handles sign-in flows; you'll need to build your own UI\nfor users to select a tenant to sign in with. The following steps show you how\nto build a simple tenant selection page with two buttons.\n\n1. Create two tenant selection elements.\n\n \u003cdiv id=\"tenant-selection-buttons\"\u003e\n \u003cbutton id=\"tenant1-select-button\" data-val=\"tenantId1\"\u003eDisplay name of Tenant 1\u003c/button\u003e\n \u003cbutton id=\"tenant2-select-button\" data-val=\"tenantId2\"\u003eDisplay name of Tenant 2\u003c/button\u003e\n \u003c/div\u003e\n\n2. Create a container element for FirebaseUI.\n\n \u003cdiv id=\"firebaseui-auth-container\"\u003e\u003c/div\u003e\n\n3. Create a configuration for each tenant.\n\n \u003cscript\u003e\n var uiConfigs = {\n 'TENANT_ID1': {\n 'signInOptions': [firebase.auth.EmailAuthProvider.PROVIDER_ID],\n 'credentialHelper': 'none',\n 'signInFlow': 'popup',\n 'callbacks': {\n 'signInSuccessWithAuthResult': function(authResult, redirectUrl) {\n // The sign in success callback.\n return false;\n }\n },\n // tosUrl and privacyPolicyUrl accept either url string or a callback\n // function.\n // Terms of service url/callback.\n tosUrl: '[YOUR_TOS_URL]',\n // Privacy policy url/callback.\n privacyPolicyUrl: function() {\n window.location.assign('[YOUR_PRIVACY_POLICY_URL]');\n }\n },\n 'TENANT_ID2': {\n 'signInOptions': [firebase.auth.GoogleAuthProvider.PROVIDER_ID],\n 'credentialHelper': 'none',\n 'signInFlow': 'popup',\n 'callbacks': {\n 'signInSuccessWithAuthResult': function(authResult, redirectUrl) {\n // The sign in success callback.\n return false;\n }\n },\n // tosUrl and privacyPolicyUrl accept either url string or a callback\n // function.\n // Terms of service url/callback.\n tosUrl: '[YOUR_TOS_URL]',\n // Privacy policy url/callback.\n privacyPolicyUrl: function() {\n window.location.assign('[YOUR_PRIVACY_POLICY_URL]');\n }\n }\n };\n \u003c/script\u003e\n\n4. Add tenant selection click handlers to render the sign-in component\n with FirebaseUI. Note that before rendering the UI component, you'll need to\n set the tenant ID on the `Auth` instance.\n\n \u003cscript\u003e\n var ui = new firebaseui.auth.AuthUI(firebase.auth());\n tenantSelectionButton.addEventListener('click', (e) =\u003e {\n var tenantId = e.target.getAttribute('data-val');\n firebase.auth().tenantId = tenantId;\n ui.reset();\n ui.start('#firebaseui-auth-container', uiConfigs[tenantId]);\n });\n \u003c/script\u003e\n\n5. Launch your app. A sign-in screen with two tenant buttons appears.\n\nWhile this example uses two simple buttons and a single page, many different\nUX flows are possible. For example, you could ask users to enter their email on\none page, then present a tenant selection screen. You could also host separate\nlogin pages for each tenant; in this case, you'd need to parse the tenant ID\nfrom the URL, and then set it on the `Auth` object.\n\nWhat's next\n-----------\n\n- [See the FirebaseUI source code on GitHub](https://github.com/firebase/firebaseui-web)"]]