rsf-auth
Reducer, actions and sagas to handle authentication with redux-saga-firebase.
Quick start
Install with:
yarn add rsf-auth
Setup the authentication reducer:
auth ...
Start the authentication saga:
{ // 👈 Pass a ReduxSagaFirebase instance and an authProvider to use // [...]}
Trigger a login:
const LoginButton = <button onClick=login>Login</button>null login LoginButton
Access the state with selectors:
// Build authentication selectorsconst loadingSelector loggedInSelector userSelector } = // 👈 Use the path you chose to store the authentication data in `combineReducers` // then, given the state: // a firebase.User instance
API
import { reducer } from 'rsf-auth'
)
Reducer (An usual (state, action) => state
redux-style reducer which stores the authentication data and responds to the authentication actions.
import { saga } from 'rsf-auth'
)
Saga (A redux-saga saga which handles login and logout requests as well as user synchronization.
It takes a ReduxSagaFirebase instance and a Firebase AuthProvider as arguments.
const authProvider = { }
import { login, ... } from 'rsf-auth/actions'
)
Actions (login()
Triggers a login with popup using the AuthProvider passed to the saga.
logout()
Triggers a logout.
import { types } from 'rsf-auth'
)
Types (Object literal containing all the types used by this library:
LOGIN: REQUEST: type`LOGIN.REQUEST` SUCCESS: type`LOGIN.SUCCESS` FAILURE: type`LOGIN.FAILURE` LOGOUT: REQUEST: type`LOGOUT.REQUEST` SUCCESS: type`LOGOUT.SUCCESS` FAILURE: type`LOGOUT.FAILURE` SYNC_USER: type`SYNC_USER`