0.0.2 • Published 3 years ago

@bung87/authflow v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

authflow

authflow provide three steps login defined in AuthFlowActions

  1. loginRequest: auth info post
  2. codeRequest: verification code (eg. sms code handle)
  3. statusRequest: refresh authed user info

Prepare

import { applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
const store = createStore(reducer, applyMiddleware(thunk))

Useage

import { deferred, fetchLogin, fetchCode, fetchStatus, AuthFlowActions } from '@bung87/authflow'

function login() {
  return fetch('http://example.com/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({}),
  }).then((res: any) => res.json())
}

let dLogin = deferred(console.log)
store.dispatch(fetchLogin(dLogin))
dLogin.resolve(login())