Loading repository data…
Loading repository data…
firebase / repository
FirebaseUI is an open-source JavaScript library for Web that provides simple, customizable UI bindings on top of Firebase SDKs to eliminate boilerplate code and promote best practices.
Firebase UI for Web brings out-of-the-box components for Firebase for your favourite frameworks:
Firebase UI v7 is a complete rewrite to support modern languages and frameworks. You can find information about the previous version, v6, in the v6-archive branch.
If you are looking to migrate, please check the MIGRATION.md guide.
To get started, make sure that the firebase package is installed in your project:
npm install firebase
Once installed, setup Firebase in your project ensuring you have configured your Firebase instance via initializeApp:
import { initializeApp } from 'firebase/app';
const app = initializeApp({ ... });
Next, follow the framework specific installation steps, for either React, Shadcn or Angular:
Install the @firebase-oss/ui-react package:
npm install @firebase-oss/ui-react@beta
Alongside your Firebase configuration, import the initializeUI function and pass your configured Firebase App instance:
import { initializeApp } from 'firebase/app';
import { initializeUI } from '@firebase-oss/ui-core';
const app = initializeApp({ ... });
const ui = initializeUI({
app,
});
Once configured, provide the ui instance to your application by wrapping it within the FirebaseUIProvider component:
import { FirebaseUIProvider } from '@firebase-oss/ui-react';
function App() {
return (
<FirebaseUIProvider ui={ui}>
...
</FirebaseUIProvider>
);
}
Ensure your application includes the bundled styles for Firebase UI (see styling for additional info).
@import "@firebase-oss/ui-styles/dist.min.css";
/* Or, if you use tailwind */
@import "@firebase-oss/ui-styles/tailwind";
That's it 🎉 You can now import components and start building:
import { SignInAuthScreen } from '@firebase-oss/ui-react';
export function MySignInPage() {
return (
<>
<header>Welcome</header>
<SignInAuthScreen onSignIn={() => { ... }} />
</>
)
}
View the reference API for a full list of components.
Firstly, ensure you have installed and setup Shadcn in your project.
Once configured, add the @firebase registry to your components.json file:
{
...
"registries": {
"@firebase": "https://firebaseopensource.com/r/{name}.json"
}
}
Next, add a Firebase UI component from the registry, e.g.
npx shadcn@latest add @firebase/sign-in-auth-screen
This will automatically install any required dependencies.
Alongside your Firebase configuration, import the initializeUI function and pass your configured Firebase App instance:
import { initializeApp } from 'firebase/app';
import { initializeUI } from '@firebase-oss/ui-core';
const app = initializeApp({ ... });
const ui = initializeUI({
app,
});
Once configured, provide the ui instance to your application by wrapping it within the FirebaseUIProvider component:
import { FirebaseUIProvider } from '@firebase-oss/ui-react';
function App() {
return (
<FirebaseUIProvider ui={ui}>
...
</FirebaseUIProvider>
);
}
That's it 🎉 You can now import components and start building:
import { SignInAuthScreen } from '@/components/sign-in-auth-screen';
export function MySignInPage() {
return (
<>
<header>Welcome</header>
<SignInAuthScreen onSignIn={() => { ... }} />
</>
)
}
View the reference API for a full list of components.
The Angular project requires that AngularFire is setup and configured before using Firebase UI.
Once you have provided the Firebase App instance to your application using provideFirebaseApp, install the Firebase UI for Angular package:
npm install @angular/fire @firebase-oss/ui-angular@beta @firebase-oss/ui-core@beta @firebase-oss/ui-styles@beta
Alongside your existing providers, add the provideFirebaseUI provider, returning a new Firebase UI instance via initializeUI:
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { initializeUI } from '@firebase-oss/ui-core';
export const appConfig: ApplicationConfig = {
providers: [
provideFirebaseApp(() => initializeApp({ ... })),
provideFirebaseUI((apps) => initializeUI({ app: apps[0] })),
]
};
Ensure your application includes the bundled styles for Firebase UI (see styling for additional info).
@import "@firebase-oss/ui-styles/dist.min.css";
/* Or for tailwind users */
@import "@firebase-oss/ui-styles/tailwind";
That's it 🎉 You can now import components and start building:
import { Component } from "@angular/core";
import { SignInAuthScreenComponent } from "@firebase-oss/ui-angular";
@Component({
selector: "sign-in-route",
standalone: true,
imports: [CommonModule, SignInAuthScreenComponent],
template: `
<header>Sign In</header>
<fui-sign-in-auth-screen (signIn)="onSignIn($event)" />
`,
})
export class SignInRoute {
onSignIn(user: User) {
// ...
}
}
View the reference API for a full list of components.
Firebase UI provides out-of-the-box styling via CSS, and provides means to customize the UI to align with your existing application or guidelines.
Note: if you are using Shadcn this section does not apply. All styles are inherited from your Shadcn configuration.
Ensure your application imports the Firebase UI CSS file. This can be handled a number of ways depending on your setup:
If your bundler supports importing CSS files from node_modules:
Via JS:
import '@firebase-oss/ui-styles/dist.min.css';
Via CSS:
@import "@firebase-oss/ui-styles/dist.min.css";
If you are using Tailwind CSS, add the Tailwind specific CSS file:
@import "tailwindcss";
@import "@firebase-oss/ui-styles/tailwind";
If none of these options apply, include the CSS file via a CDN:
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@firebase-oss/ui-styles/dist/dist.min.css">
</head>
Out of the box, Firebase UI provides a neutral light and dark theme with some opinionated styling (colors, border radii etc). These are all controlled via CSS variables, allowing you to update these at will to match any existing UI design guidelines. To modify the variables, override the following CSS variables:
:root {
/* The primary color is used for the button and link colors */
--fui-primary: ...;
/* The primary hover color is used for the button and link colors when hovered */
--fui-primary-hover: ...;
/* The primary surface color is used for the button text color */
--fui-primary-surface: ...;
/* The text color used for body text */
--fui-text: ...;
/* The muted text color used for body text, such as subtitles */
--fui-text-muted: ...;
/* The background color of the cards */
--fui-background: ...;
/* The border color used for none input fields */
--fui-border: ...;
/* The input color used for input fields */
--fui-input: ...;
/* The error color used for error messages */
--fui-error: ...;
/* The radius used for the input fields */
--fui-radius: ...;
/* The radius used for the cards */
--fui-radius-card: ...;
}
Out of the box, Firebase UI applies sensible default behaviors for how the UI should handle specific scenarios which may occur during user flows. You can however customize this behavior by modifying your initializeUI to provide an array of "behaviors", for example:
import { requireDisplayName } from '@firebase-oss/ui-core';
const ui = initializeUI({
app,
behaviors: [
requireDisplayName(),
],
});
autoAnonymousLoginThe autoAnonymousLogin behavior will automatically sign users in via anonymous authentication when initialized. Whilst authenticating, the Firebase UI state will be set to "loading", allowing you to block the loading of the application if you wish.
import { autoAnonymousLogin } from '@firebase-oss/ui-core';
const ui = initializeUI({
app,
behaviors: [autoAnonymousLogin()],
});
autoUpgradeAnonymousUsersThe autoUpgradeAnonymousUsers behavior will automatically upgrade a user who is anonymously authenticated with your application upon a successful sign in (including OAuth). You can optionally provide a callback to handle an upgrade (such as merging account data). During the async callback, the UI will stay in a pending state.
import { autoUpgradeAnonymousUsers } from '@firebase-oss/ui-core';
const ui = initializeUI({
app,
behaviors: [autoUpgradeAnonymousUsers({
async onUpgrade(ui, oldUserId, credential) {
// Some account upgrade logic.
}
})],
});
recaptchaVerificationThe recaptchaVerification behavior allows you to customize how the reCAPTCHA provider is rendered during some UI flows (such as Phone Authentication).
By default, the reCAPTCHA UI will be rendered in "invisible" mode. To override this:
import { recaptchaVerification } from '@firebase-oss/ui-core';
const ui = initializeUI({
app,
behaviors: [recaptchaVerification({
size: "compact", // "normal" | "invisible" | "compact"
theme: "dark", // "light" | "dark"
})],
});
providerRedirectStrategyThe providerRedirectStrategy behavior redirects any external provider authentication (e.g. OAuth) via a redirect flow.
import { providerRedirectStrategy } from '@firebase-oss/ui-core';
const ui = initializeUI({
app,
behaviors: [providerRedirectStrategy()],
});
providerPopupStrategyThe providerPopupStrategy behavior causes any external provider authentication (e.g. OAuth) to be handled via a popup window. This is the default strategy.
import { providerPopupStrategy } from '@firebase-oss/ui-core';
const ui = initializeUI({
app,
behaviors: [providerPopupStrategy()],
});
oneTapSignInThe oneTapSignIn behavior triggers the Google One Tap experience to render.
Note: This behavior requires that Google Sign In is enabled as an authentication method on the Firebase Console. Once enabled, you can obtain the required clientId via the "Web SDK configuration" settings on the Console.
The One Tap popup can be