in sample/authui-react/src/components/firebaseui.tsx [130:187]
componentDidMount() {
// Fetch configuration via reserved Firebase Hosting URL.
fetch('/__/firebase/init.json').then((response) => {
return response.json();
})
.then((config: any) => {
const configs: any = {};
configs[config.apiKey] = {
authDomain: config.authDomain,
callbacks: {
// The callback to trigger when tenant selection page is shown.
selectTenantUiShown: () => {
this.setState({
title: 'Select Employer',
});
},
// The callback to trigger when tenant selection page is hidden.
selectTenantUiHidden: () => {
this.setState({
title: undefined,
});
},
// The callback to trigger when the sign-in page
// is shown.
signInUiShown: (tenantId: string | null) => {
const configKey = tenantId ? tenantId : '_';
const title = (tenantsConfig as any)[configKey].displayName;
this.setState({
title,
});
},
beforeSignInSuccess: (user: any) => {
// Do additional processing on user before sign-in is
// complete.
return Promise.resolve(user);
},
},
displayMode: 'optionsFirst',
// The terms of service URL and privacy policy URL for the page
// where the user selects a tenant or enters an email for tenant/provider
// matching.
tosUrl: '/tos',
privacyPolicyUrl: '/privacypolicy',
tenants: tenantsConfig,
};
// This will handle the underlying handshake for sign-in, sign-out,
// token refresh, safe redirect to callback URL, etc.
const handler = new firebaseui.auth.FirebaseUiHandler(
'#firebaseui-container', configs);
try {
const ciapInstance = new ciap.Authentication(handler);
ciapInstance.start();
} catch (e) {
console.log(e);
}
})
.catch(console.log);
}