Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
react-firebaseui
Advanced tools
React wrapper for firebaseui: Javascript library for customizable UI on top of Firebase SDK
FirebaseUI React Components provides React Wrappers on top of the Firebase UI Web library and notably Firebase UI Auth.
FirebaseUI Auth provides a drop-in auth solution that handles the UI flows for signing in users with email addresses and passwords, and Identity Provider Sign In using Google, Facebook and others. It is built on top of Firebase Auth.
For an example on how to use the FirebaseAuth react component have a look at the example folder.
Install the npm package in your React app:
npm install --save react-firebaseui
You also need the firebase
package installed which is a peer dependency:
npm install --save firebase
In your app:
FirebaseAuth
or the StyledFirebaseAuth
component from react-firebaseui
and import firebase
.FirebaseAuth
component in your template passing it the Firebase UI configuration and a Firebase Auth instance.FirebaseAuth
vs StyledFirebaseAuth
There are two components that allow you to add FirebaseUI auth to your application: FirebaseAuth
and StyledFirebaseAuth
. The difference is that FirebaseAuth
has a reference to the Firebase UI CSS (it requires
the CSS) whereas StyledFirebaseAuth
includes the CSS directly in its built. For simplicity you should use StyledFirebaseAuth
and for better performances and build sizes you should use FirebaseAuth
. FirebaseAuth
is meant to be used with a CSS/style loader as part of yor webpack built configuration. See the Packing your app section
StyledFirebaseAuth
with a redirectBelow is an example on how to use FirebaseAuth
with a redirect upon sign-in:
// Import FirebaseAuth and firebase.
import React from 'react';
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth';
import firebase from 'firebase';
// Configure Firebase.
const config = {
apiKey: 'AIzaSyAeue-AsYu76MMQlTOM-KlbYBlusW9c1FM',
authDomain: 'myproject-1234.firebaseapp.com',
// ...
};
firebase.initializeApp(config);
// Configure FirebaseUI.
const uiConfig = {
// Popup signin flow rather than redirect flow.
signInFlow: 'popup',
// Redirect to /signedIn after sign in is successful. Alternatively you can provide a callbacks.signInSuccess function.
signInSuccessUrl: '/signedIn',
// We will display Google and Facebook as auth providers.
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.FacebookAuthProvider.PROVIDER_ID
]
};
class SignInScreen extends React.Component {
render() {
return (
<div>
<h1>My App</h1>
<p>Please sign-in:</p>
<StyledFirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()}/>
</div>
);
}
}
FirebaseAuth
with local state.Below is an example on how to use FirebaseAuth
with a state change upon sign-in:
// Import FirebaseAuth and firebase.
import React from 'react';
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth';
import firebase from 'firebase';
// Configure Firebase.
const config = {
apiKey: 'AIzaSyAeue-AsYu76MMQlTOM-KlbYBlusW9c1FM',
authDomain: 'myproject-1234.firebaseapp.com',
// ...
};
firebase.initializeApp(config);
class SignInScreen extends React.Component {
state = {
signedIn: false // Local signed-in state.
};
// Configure FirebaseUI.
uiConfig = {
// Popup signin flow rather than redirect flow.
signInFlow: 'popup',
// We will display Google and Facebook as auth providers.
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.FacebookAuthProvider.PROVIDER_ID
],
// Avoid redirects after sign-in.
callbacks: {
signInSuccess: () => false
}
};
// Listen to the Firebase Auth state and set the local state.
componentWillMount() {
firebase.auth().onAuthStateChanged((user) => {
this.setState({signedIn: !!user});
});
}
render() {
if (!this.state.signedIn) {
return (
<div>
<h1>My App</h1>
<p>Please sign-in:</p>
<StyledFirebaseAuth uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
</div>
);
}
return (
<div>
<h1>My App</h1>
<p>Welcome {firebase.auth().currentUser.displayName}! You are now signed-in!</p>
<a onClick={() => firebase.auth().signOut()}>Sign-out</a>
</div>
);
}
}
To allow for further configuration you can access the firebaseUI instance before it is started.
To do this you can pass a uiCallback
callback function that wil be passed the Firebase UI instance. For example here is how to enable the disableAutoSignIn()
option:
// ...
render() {
return (
<div>
<h1>My App</h1>
<p>Please sign-in:</p>
<StyledFirebaseAuth uiCallback={ui => ui.disableAutoSignIn()} uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
</div>
);
}
If you are using the StyledFirebaseAuth
component there should not be special configuration needed to package your app since the CSS is already included within the component. if you would like to extract the CSS you should use the FirebaseAuth
component instead.
The FirebaseAuth
needs a global CSS to get proper styling. The CSS is already imported within FirebaseAuth
.
If you are using webpack you'll need to add CSS loaders:
{
module: {
rules: [
{
test: /\.css/,
use: [ 'style-loader', 'css-loader' ]
}
]
}
}
PS: make sure your rule does not exclude /node_modules/
as this is where the library, and therefore, the CSS is located.
If you are using ExtractTextPlugin
to extract a CSS file from the required CSS files you would typically use:
{
plugins: [new ExtractTextPlugin('./bundle.css')],
module: {
rules: [
{
test: /\.css/,
loader: ExtractTextPlugin.extract(
{
fallback: 'style-loader',
use: ['css-loader']
})
}
]
}
}
PS: make sure your rule does not exclude /node_modules/
as this is where the library, and therefore, the CSS is located.
If you are using CSS modules in your app you need to handle the CSS files in /node_modules/
in a separate loader so that they are imported as global CSS files and not modules. Your setup could look like:
{
plugins: [new ExtractTextPlugin('./bundle.css')],
module: {
rules: [
// CSS loaders for CSS modules in your project. We exclude CSS files in ./node_modules
{
test: /\.css$/,
exclude: [/\.global\./, /node_modules/],
loader: ExtractTextPlugin.extract(
{
fallback: 'style-loader',
use:[
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: true,
autoprefixer: true,
minimize: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
}
]
})
},
// CSS loaders for global CSS files which includes files in ./node_modules
{
test: /\.css/,
include: [/\.global\./, /node_modules/],
loader: ExtractTextPlugin.extract(
{
fallback: 'style-loader',
use: ['css-loader']
})
}
]
}
}
To change the styling of the FirebaseAuth
or the StyledFirebaseAuth
widget you can override some of its CSS. You can import a CSS that will be included globally in your packed application. For instance create a firebaseui-overrides.global.css
file and import it in your app:
import './firebaseui-overrides.global.css'; // Import globally.
Note: If you are using the "With ExtractTextPlugin and CSS modules" Webpack build rule above, the
.global.css
suffixe will make sure the CSS file is imported globally and not ran through modules support.
If you would like to see an example of styling, have a look at the example app.
In the case where you would need to load multiple instances of FirebaseAuth
at the same time you need to set them up with a different ID using the elementId
attribute. For instance:
<StyledFirebaseAuth elementId="auth_1" uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
<StyledFirebaseAuth elementId="auth_2" uiConfig={this.otherUiConfig} firebaseAuth={firebase.auth()}/>
We'd love that you contribute to the project. Before doing so please read our Contributor guide.
© Google, 2011. Licensed under an Apache-2 license.
FAQs
React wrapper for firebaseui: Javascript library for customizable UI on top of Firebase SDK
The npm package react-firebaseui receives a total of 7,007 weekly downloads. As such, react-firebaseui popularity was classified as popular.
We found that react-firebaseui demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.