1.0.0 • Published 7 years ago
hybrid-auth-container v1.0.0
Hybrid Auth Container
A container for React and React Native
How it works
After you defined a view for each case, the container will inject the props on your view, enabling functions to authenticate the user and callbacks to deal with this authentications.
<AuthContainer
redirectView={() => (<div />)}
routeAfterCheck={'login'}
loginView={Login}
onRouteChange={(route) => this.setState({ route })}
route={this.state.route}
onUserAuthenticated={(authObj) => this.onUserAuthenticated(authObj)}
checkUser={()=>this.checkUser()}
validateUser={(user) => this.validateUser(user)} />Container Props
route(string) - current route. Default routes:- "redirect" - View that is shown when checking if user is authenticated
- "login" - Login View
- "signUp" - SignUp View
- "recoverPassword" - Password recovery steps
checkUser(function) - function to check if user is logged (check on session or cache...)routeAfterCheck(string) - route to send user if it's not authenticated (checked onredirectView)validateUser(function) - will receive a user and return true or false, checking if it's a valid uservalidateEmail(function) - will receive a email and return true or false, checking if it's a valid email
Callbacks
onUserAuthenticated- generic callback that will be called wherever the user is authenticatedonLoginFailedonLoginSuccessonSocialLoginFailedonSocialLoginSuccessonSingUpFailedonSingUpSuccessonPasswordResetFailonRouteChangeonStepChange
Views
Views can be passed as props or children component. If passed as props, the name of prop will be route + 'View'. Examples:
- loginView
- signUpView
- redirectView
- recoverPasswordView
View Props
Props that the container will inject on the view inside auth object.
loading- true if the http request is loadingerror- error object on App Masters patterngetFieldError- function to get error from a specific fieldchangeRoute- function to change route. Will trigger theonRouteChangecallback
On login view
doLogin- login function using email and passworddoSocialLogin- login/sign up using a social network. Pass the user object and a string with the network used, like "facebook"
On signUp view
doSignUp- sing up function using email and passworddoSocialLogin- login/sign up using a social network. Pass the user object and a string with the network used, like "facebook"
On recoverPassword view
changeSteprecoverySteprequestCodevalidateCoderesetPassword
1.0.0
7 years ago