Skip to content

Commit 64c5ece

Browse files
committed
Added error handling screen
1 parent 1ffe590 commit 64c5ece

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from 'react'
2+
3+
import {
4+
View,
5+
Text,
6+
NativeModules
7+
} from 'react-native'
8+
9+
import env from '../../../../config/environment';
10+
import { Container, Header, Title, Content, Button } from 'native-base';
11+
import appStyles from '../../../styles/app';
12+
13+
const ERRORS = {
14+
'badUsernamePassword': 1
15+
}
16+
17+
export class ErrorHandling extends React.Component {
18+
19+
constructor(props) {
20+
super(props);
21+
22+
this.state = {
23+
lastError: null
24+
}
25+
}
26+
27+
componentWillMount() {
28+
const {firestack} = this.props;
29+
firestack.auth.listenForAuth((user) => {
30+
console.log('user -->', user);
31+
});
32+
}
33+
34+
35+
componentWillUnmount() {
36+
const {firestack} = this.props;
37+
firestack.auth.unlistenForAuth();
38+
}
39+
40+
generateError(key) {
41+
const {firestack} = this.props;
42+
43+
return () => {
44+
switch(key) {
45+
case ERRORS['badUsernamePassword']:
46+
firestack.auth.signInWithEmail('ari@fullstack.io', 'definitely_not_my_password')
47+
.then(user => console.log('Success'))
48+
.catch(err => {
49+
console.log('Error with signInWithEmail', err);
50+
this.setState({lastError: err})
51+
})
52+
break;
53+
}
54+
}
55+
}
56+
57+
render() {
58+
return (
59+
<Container>
60+
<Content>
61+
<Button
62+
onPress={this.generateError(ERRORS['badUsernamePassword'])}>
63+
Generate
64+
</Button>
65+
</Content>
66+
</Container>
67+
)
68+
}
69+
70+
}
71+
72+
export default ErrorHandling

app/views/Authentication/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import List from '../../components/List/List'
1212
import Email from './Demos/Email';
1313
import Providers from './Demos/Providers';
1414
import Anonymous from './Demos/Anonymous';
15+
import ErrorHandling from './Demos/ErrorHandling';
1516

1617
export const Routes = {
1718
'email': {
@@ -31,6 +32,12 @@ export const Routes = {
3132
title: 'Anonymous login',
3233
Component: Anonymous
3334
}
35+
},
36+
'error_handling': {
37+
route: {
38+
title: 'Error handling',
39+
Component: ErrorHandling
40+
}
3441
}
3542
}
3643

0 commit comments

Comments
 (0)