File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change 11import React , { Component } from "react" ;
2+ import { Text } from "react-native" ;
3+
24import firebase from "firebase" ;
5+
36import { Button , Card , CardSection , Input } from "./common" ;
47
58class LoginForm extends Component {
69 constructor ( props ) {
710 super ( props ) ;
811 this . state = {
912 email : "" ,
10- password : ""
13+ password : "" ,
14+ error : ""
1115 } ;
1216 }
1317
14- onButtonPress = ( ) => {
18+ onButtonPress = async ( ) => {
1519 const { email, password } = this . state ;
16- firebase . auth ( ) . signInAndRetrieveDataWithEmailAndPassword ( email , password ) ;
20+ try {
21+ await firebase . auth ( ) . signInAndRetrieveDataWithEmailAndPassword ( email , password ) ;
22+ } catch ( err ) {
23+ try {
24+ await firebase . auth ( ) . createUserWithEmailAndPassword ( email , password ) ;
25+ } catch ( error ) {
26+ this . setState ( { error : "Authentication Failed" } ) ;
27+ }
28+ }
1729 } ;
1830
1931 render ( ) {
@@ -36,6 +48,9 @@ class LoginForm extends Component {
3648 secureTextEntry
3749 />
3850 </ CardSection >
51+
52+ < Text style = { styles . errorTextStyle } > { this . state . error } </ Text >
53+
3954 < CardSection >
4055 < Button onPress = { this . onButtonPress } > Login</ Button >
4156 </ CardSection >
@@ -44,4 +59,12 @@ class LoginForm extends Component {
4459 }
4560}
4661
62+ const styles = {
63+ errorTextStyle : {
64+ fontSize : 20 ,
65+ alignSelf : "center" ,
66+ color : "red"
67+ }
68+ } ;
69+
4770export default LoginForm ;
You can’t perform that action at this time.
0 commit comments