New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

redux-fire-auth

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-fire-auth - npm Package Compare versions

Comparing version 0.0.1-beta.3 to 1.0.0-rc.1

.travis.yml

8

package.json
{
"name": "redux-fire-auth",
"version": "0.0.1-beta.3",
"description": "Helper to keep the redux state in sync with the firebase auth session.",
"version": "1.0.0-rc.1",
"description": "Helper to keep the Redux State in sync with the Firebase Auth State.",
"main": "dist/index.js",

@@ -9,3 +9,4 @@ "scripts": {

"test": "cross-env NODE_ENV=test nyc -x src/**/*.test.js mocha src/**/*.test.js --require babel-core/register",
"build": "npm run test && npm run lint && cross-env NODE_ENV=production babel src --ignore test.js --source-maps --out-dir dist"
"build": "npm run test && npm run lint && cross-env NODE_ENV=production babel src --ignore test.js --source-maps --out-dir dist",
"report": "nyc report -x ./src/index.spec.js --reporter=text-lcov | coveralls"
},

@@ -34,2 +35,3 @@ "repository": {

"chai": "^4.1.2",
"coveralls": "^3.0.0",
"cross-env": "^5.1.1",

@@ -36,0 +38,0 @@ "eslint": "^4.13.1",

@@ -1,2 +0,88 @@

# firebase-redux-auth-manager
Helper to keep the redux state in sync with the firebase auth session.
# redux-fire-auth
Helper to keep the Redux State in sync with the Firebase Auth State.
[![Build Status](https://travis-ci.org/flasd/react-classlist-helper.svg?branch=master)](https://travis-ci.org/flasd/redux-fire-auth) [![Coverage Status](https://coveralls.io/repos/github/flasd/redux-fire-auth/badge.svg?branch=master)](https://coveralls.io/github/flasd/redux-fire-auth?branch=master) [![npm version](https://badge.fury.io/js/redux-fire-auth.svg)](https://www.npmjs.com/package/redux-fire-auth) [![npm](https://img.shields.io/badge/Licence-MIT-blue.svg)](https://github.com/flasd/redux-fire-auth/blob/master/LICENSE) [![code style](https://img.shields.io/badge/Code%20Style-Airbnb-orange.svg)](https://www.npmjs.com/package/eslint-config-airbnb)
### Why?
When you start playing with Firebase auth, you will soon realize that when the page refreshes, you loose authentication state until the SDK kicks back in.
Wouldn't it be nice if you could tell if the Firebase SDK have finished initializing and if there's a logged in user? Well :wink:
### Setup
First, obviously,
```
$ npm install redux-fire-auth --save
```
Then, you'll need 2 things:
```javascript
import firebase from 'firebase';
import { createStore, combineReducers } from 'redux';
import { reduxFireAuthReducer, init } from 'redux-fire-auth';
import * as yourReducers from './your-reducers.js';
const store = createStore(
combineReducers({
'fireAuth': reduxFireAuthReducer,
...yourReducers,
}),
);
const authInstance = firebase.auth();
init(store, authInstance);
```
The `init` function binds Firebase's `onAuthStateChanged` with action creators. Whenever there's a authStateChanged event, the redux state will sync automatically.
**Note:** If you'd want to use something other than `fireAuth` to bind the reducer to, you need to pass the key you are using to `init(store, authInstance, key)` as the third argument.
### Usage
When you call `store.getState().fireAuth` you'll get an object with three properties:
##### isLoading: bool
True while the Firebase SDK is initializing, then always false.
##### hasAuth: bool
False while the Firebase SDK is initializing, then if the SDK recovers the session it's true, else it stays false.
##### user: Firebase.User | null
null while the Firebase SDK is initializing, then if the SDK recovers the session it's the User.toJSON() object, without the User methods provided by firebase, else it stays null.
### Example
I'm assuming you know how to work with React and React-Redux for this example :grin:
```javascript
import React from 'react';
import { connect } from 'react-redux';
export function App({ isLoading, hasAuth, user }) {
if (isLoading) {
return (
<div> Loading... </div>
);
}
if (hasAuth) {
return (
<div> Hello { user.displayName } </div>
);
}
return (
<div> Please sign in. </div>
);
}
export function mapStateToProps(state) {
return state.fireAuth;
}
export default connect(mapStateToProps)(App);
```
### Licence
MIT all the way. Let's create awesome stuff! :rocket:
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc