Skip to content

Commit a9f65ed

Browse files
author
Nicolas Garnier
committed
Initial import
1 parent 689adb0 commit a9f65ed

21 files changed

+1053
-5
lines changed

Diff for: .babelrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
"react",
4+
["env", {
5+
"targets": { "node": "4.1" },
6+
"loose": true,
7+
"modules": "commonjs"
8+
}]
9+
],
10+
"plugins": [
11+
"transform-class-properties",
12+
"transform-object-rest-spread"
13+
]
14+
}

Diff for: .editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true

Diff for: .eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
example/public/
2+
node_modules/

Diff for: .eslintrc

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"extends": [
3+
"plugin:flowtype/recommended",
4+
"google",
5+
"prettier",
6+
"prettier/react",
7+
"plugin:react/recommended"
8+
],
9+
"plugins": [
10+
"flowtype",
11+
"prettier"
12+
],
13+
"parser": "babel-eslint",
14+
"parserOptions": {
15+
"ecmaVersion": 2016,
16+
"sourceType": "module",
17+
"ecmaFeatures": {
18+
"jsx": true
19+
}
20+
},
21+
"env": {
22+
"es6": true,
23+
"browser": true,
24+
"node": true,
25+
"jest": true
26+
},
27+
"globals": {
28+
"firebaseUi": true,
29+
"uiConfig": true,
30+
"jQuery": true,
31+
"swal": true,
32+
"latinize": true,
33+
"componentHandler": true,
34+
"friendlyPix": true,
35+
"page": true,
36+
"ga": true,
37+
"firebase": true,
38+
"gapi": true
39+
}
40+
}

Diff for: .gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*.pyc
2+
/example/node_modules
3+
/node_modules
4+
/firebase-debug.log
5+
/example/src/firebase-config.json
6+
/example/.firebaserc

Diff for: CONTRIBUTING.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# How to Contribute
2+
3+
We'd love to accept your patches and contributions to this project. There are
4+
just a few small guidelines you need to follow.
5+
6+
## Contributor License Agreement
7+
8+
Contributions to this project must be accompanied by a Contributor License
9+
Agreement. You (or your employer) retain the copyright to your contribution,
10+
this simply gives us permission to use and redistribute your contributions as
11+
part of the project. Head over to <https://cla.developers.google.com/> to see
12+
your current agreements on file or to sign a new one.
13+
14+
You generally only need to submit a CLA once, so if you've already submitted one
15+
(even if it was for a different project), you probably don't need to do it
16+
again.
17+
18+
## Code reviews
19+
20+
All submissions, including submissions by project members, require review. We
21+
use GitHub pull requests for this purpose. Consult
22+
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23+
information on using pull requests.

Diff for: LICENSE

+13-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"License" shall mean the terms and conditions for use, reproduction,
1010
and distribution as defined by Sections 1 through 9 of this document.
1111

12-
"Licensor" shall mean the copyright owner or entity authorized by
12+
"Licensor" shall mean the dcopyright owner or entity authorized by
1313
the copyright owner that is granting the License.
1414

1515
"Legal Entity" shall mean the union of the acting entity and all
@@ -178,15 +178,15 @@
178178
APPENDIX: How to apply the Apache License to your work.
179179

180180
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "{}"
181+
boilerplate notice, with the fields enclosed by brackets "[]"
182182
replaced with your own identifying information. (Don't include
183183
the brackets!) The text should be enclosed in the appropriate
184184
comment syntax for the file format. We also recommend that a
185185
file or class name and description of purpose be included on the
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2015 Google Inc
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.
@@ -199,3 +199,13 @@
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201201
limitations under the License.
202+
203+
All code in any directories or sub-directories that end with *.html or
204+
*.css is licensed under the Creative Commons Attribution International
205+
4.0 License, which full text can be found here:
206+
https://creativecommons.org/licenses/by/4.0/legalcode.
207+
208+
As an exception to this license, all html or css that is generated by
209+
the software at the direction of the user is copyright the user. The
210+
user has full ownership and control over such content, including
211+
whether and how they wish to license it.

Diff for: README.md

+246-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,246 @@
1-
# firebaseui-web-react
2-
React Wrapper for firebaseUI Web
1+
# FirebaseUI Web -- Auth for React
2+
3+
FirebaseUI for react provides a React Wrapper on top of the [Firebase UI Web library](https://github.com/firebase/firebaseui-web/) and notably Firebase UI Auth.
4+
5+
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.
6+
7+
8+
## Installation and Usage
9+
10+
> For an example on how to use the FirebaseAuth react component have a look at the [example](./example) folder.
11+
12+
Install the npm package in your React app:
13+
14+
```bash
15+
npm install --save react-firebaseui
16+
```
17+
18+
You also need the `firebase` package installed which is a peer dependency:
19+
20+
```bash
21+
npm install --save firebase
22+
```
23+
24+
In your app:
25+
1. Import the `FirebaseAuth` component from `react-firebaseui` and import `firebase`.
26+
2. Configure Firebase as described in [the Firebase Docs](https://firebase.google.com/docs/web/setup).
27+
3. Configure Firebase UI as described in [firebase/firebaseui-web](https://github.com/firebase/firebaseui-web#configuration).
28+
4. Use the `FirebaseAuth` component in your template passing it the configuration and a Firebase Auth instance.
29+
30+
31+
### Using `FirebaseAuth` with a redirect
32+
33+
Below is an example on how to use `FirebaseAuth` with a redirect upon sign-in:
34+
35+
```js
36+
// Import FirebaseAuth and firebase.
37+
import React from 'react';
38+
import { FirebaseAuth } from 'react-firebaseui';
39+
import firebase from 'firebase';
40+
41+
// Configure Firebase.
42+
const config = {
43+
apiKey: 'AIzaSyAeue-AsYu76MMQlTOM-KlbYBlusW9c1FM',
44+
authDomain: 'myproject-1234.firebaseapp.com',
45+
// ...
46+
};
47+
firebase.initializeApp(config);
48+
49+
// Configure FirebaseUI.
50+
const uiConfig = {
51+
// Popup signin flow rather than redirect flow.
52+
signInFlow: 'popup',
53+
// Redirect to /signedIn after sign in is successful. Alternatively you can use provide a callbacks.signInSuccess function.
54+
signInSuccessUrl: '/signedIn',
55+
// We will display Google and Facebook as auth providers.
56+
signInOptions: [
57+
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
58+
firebase.auth.FacebookAuthProvider.PROVIDER_ID
59+
]
60+
};
61+
62+
class SignInScreen extends React.Component {
63+
render() {
64+
return (
65+
<h1>My App</h1>
66+
<p>Please sign-in:</p>
67+
<FirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()}/>
68+
);
69+
}
70+
}
71+
```
72+
73+
### Using `FirebaseAuth` with local state.
74+
75+
Below is an example on how to use `FirebaseAuth` with a state change upon sign-in:
76+
77+
```js
78+
// Import FirebaseAuth and firebase.
79+
import React from 'react';
80+
import { FirebaseAuth } from 'react-firebaseui';
81+
import firebase from 'firebase';
82+
83+
// Configure Firebase.
84+
const config = {
85+
apiKey: 'AIzaSyAeue-AsYu76MMQlTOM-KlbYBlusW9c1FM',
86+
authDomain: 'myproject-1234.firebaseapp.com',
87+
// ...
88+
};
89+
firebase.initializeApp(config);
90+
91+
class SignInScreen extends React.Component {
92+
93+
// Configure FirebaseUI.
94+
uiConfig = {
95+
// Popup signin flow rather than redirect flow.
96+
signInFlow: 'popup',
97+
// Redirect to /signedIn after sign in is successful. Alternatively you can use provide a callbacks.signInSuccess function.
98+
signInSuccessUrl: '/signedIn',
99+
// We will display Google and Facebook as auth providers.
100+
signInOptions: [
101+
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
102+
firebase.auth.FacebookAuthProvider.PROVIDER_ID
103+
],
104+
callbacks: {
105+
signInSuccess: () => {
106+
this.setState({signedIn: true});
107+
return false;
108+
}
109+
}
110+
};
111+
112+
state = {
113+
signedIn: false
114+
};
115+
116+
render() {
117+
if (!this.state.signedIn) {
118+
return (
119+
<h1>My App</h1>
120+
<p>Please sign-in:</p>
121+
<FirebaseAuth uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
122+
);
123+
}
124+
return (
125+
<h1>My App</h1>
126+
<p>Welcome! You are now signed-in!</p>
127+
);
128+
}
129+
}
130+
```
131+
132+
## Packing your app
133+
134+
The `FirebaseAuth` component needs a global CSS to get proper styling. The CSS is already import within `FirebaseAuth`.
135+
If you are using webpack you'll need to add [CSS loaders](https://github.com/webpack-contrib/css-loader):
136+
137+
```json
138+
{
139+
module: {
140+
rules: [
141+
{
142+
test: /\.css/,
143+
use: [ 'style-loader', 'css-loader' ]
144+
}
145+
]
146+
}
147+
}
148+
```
149+
150+
### With ExtractTextPlugin
151+
152+
If you are using [`ExtractTextPlugin`](https://github.com/webpack-contrib/extract-text-webpack-plugin) to extract a CSS file from the required CSS files you would typically use:
153+
154+
```json
155+
{
156+
plugins: [new ExtractTextPlugin('./bundle.css')],
157+
module: {
158+
rules: [
159+
{
160+
test: /\.css/,
161+
loader: ExtractTextPlugin.extract(
162+
{
163+
fallback: 'style-loader',
164+
use: ['css-loader']
165+
})
166+
}
167+
]
168+
}
169+
}
170+
```
171+
172+
### With ExtractTextPlugin and CSS modules
173+
174+
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:
175+
176+
```json
177+
{
178+
plugins: [new ExtractTextPlugin('./bundle.css')],
179+
module: {
180+
rules: [
181+
{
182+
test: /\.css$/,
183+
exclude: [/\.global\./, /node_modules/],
184+
loader: ExtractTextPlugin.extract(
185+
{
186+
fallback: 'style-loader',
187+
use:[
188+
{
189+
loader: 'css-loader',
190+
options: {
191+
importLoaders: 1,
192+
modules: true,
193+
autoprefixer: true,
194+
minimize: true,
195+
localIdentName: '[name]__[local]___[hash:base64:5]'
196+
}
197+
}
198+
]
199+
})
200+
},
201+
{
202+
test: /\.css/,
203+
include: [/\.global\./, /node_modules/],
204+
loader: ExtractTextPlugin.extract(
205+
{
206+
fallback: 'style-loader',
207+
use: ['css-loader']
208+
})
209+
}
210+
]
211+
}
212+
}
213+
```
214+
215+
## Styling
216+
217+
To change the styling of the `FirebaseAuth` widget you can override its CSS. You can import a CSS that will be included globally in your packed application. For instance create a `firebaseui-overrides.globlal.css` file and import it in your app:
218+
219+
```js
220+
import './firebaseui-styling.global.css'; // Import globally.
221+
```
222+
223+
> 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.
224+
225+
If you would like to see an example of styling, have a look at the [example app](./example).
226+
227+
228+
## Using multiple instances
229+
230+
In the rare case where you would need to load multiple instances of `FirebaseAuth` at the same time you need to pass them a different ID using the `elementId` attribute. For instance:
231+
232+
```js
233+
<FirebaseAuth elementId="auth_1" uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
234+
<FirebaseAuth elementId="auth_2" uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
235+
236+
```
237+
238+
239+
## Contributing
240+
241+
We'd love that you contribute to the project. Before doing so please read our [Contributor guide](CONTRIBUTING.md).
242+
243+
244+
## License
245+
246+
© Google, 2011. Licensed under an [Apache-2](LICENSE) license.

0 commit comments

Comments
 (0)