@typeheim/fire-auth
v0.1.0
Published
Firebase authentication library
Downloads
9
Maintainers
Readme
FireAuth is Firebase auth library based on Rx principles.
Installation
Install package:
yarn add @typeheim/fire-auth
//or
npm -i @typeheim/fire-auth
Setup singleton services:
import { FireAuth, FireAuthSession } from '@typeheim/fire-auth'
const auth = firebase.auth()
FireAuth.setAuthDriver(auth)
FireAuthSession.setAuthDriver(auth)
Alternatively you can create your own singleton services or set up DI in your framework:
import { AuthManager, AuthSession } from '@typeheim/fire-auth'
const auth = firebase.auth()
const Auth = new AuthManager()
const Session = new AuthSession()
Auth.setAuthDriver(auth)
Session.setAuthDriver(auth)
Sample
import { FireAuth, FireAuthSession, AuthProvidersList } from '@typeheim/fire-auth'
// through provider
FireAuth.throughProvider(AuthProvidersList.Google).signInWithPopup()
// using email/password flow
FireAuth.signIn(new PasswordAuth('email', 'password'))
// getting user object
FireAuthSession.userStream.subscribe(user => /*do your magick*/)
// gedding auth status
FireAuthSession.isLoggedInStream.subscribe(isLoggedIn => /*do your magick*/)
// gedding access token
FireAuthSession.accessTokenStream.subscribe(token => /*do your magick*/)