Skip to content

Commit dc66cc1

Browse files
committed
login with email and password
1 parent fb33b55 commit dc66cc1

File tree

2 files changed

+56
-19
lines changed

2 files changed

+56
-19
lines changed

src/views/Auth/SingIn.jsx

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,40 @@ import { fetchUser, singup } from '../../store/actions/user';
1919
import auth from '@react-native-firebase/auth';
2020
import { GoogleSignin } from '@react-native-google-signin/google-signin';
2121

22-
// GoogleSignin.configure({
23-
// webClientId: '897362002662-kihdbmlmur6gsj5s3mi7m9o808j0m5s4.apps.googleusercontent.com',
24-
// offlineAccess: true,
25-
// });
26-
2722
class SingIn extends Component {
2823
state = {
2924
name: 'Aleatorio',
30-
email: 'email@gmail.com',
31-
password: '',
25+
email: 'jane.doe@example.com',
26+
password: 'SuperSecretPassword!',
3227
};
3328

3429
iosLogin = () => {
3530
this.props.onLogin({...this.state});
3631
};
3732

3833
login = () => {
39-
this.props.onLogin({
40-
id: 0,
41-
name: this.state.name,
42-
email: this.state.email,
43-
identy: null,
44-
});
34+
auth()
35+
.signInWithEmailAndPassword(this.state.email, this.state.password)
36+
.then(() => {
37+
this.props.onLogin({
38+
id: 0,
39+
name: this.state.name,
40+
email: this.state.email,
41+
identy: null,
42+
});
43+
console.log('user singed in');
44+
})
45+
.catch(error => {
46+
if (error.code === 'auth/email-already-in-use') {
47+
console.log('That email address is already in use!');
48+
}
49+
50+
if (error.code === 'auth/invalid-email') {
51+
console.log('That email address is invalid!');
52+
}
53+
54+
console.error(error);
55+
});
4556
};
4657

4758
googleLogin = async () => {
@@ -61,6 +72,15 @@ class SingIn extends Component {
6172
console.log('Login com Google realizado com sucesso!');
6273

6374
this.setState({...this.state, email: idToken});
75+
76+
fetch('https://randomuser.me/api/')
77+
.then(res => res.json())
78+
.then(
79+
(result) => {
80+
this.setState({...this.state, name: result.results[0].name.first});
81+
}
82+
);
83+
6484
this.props.onGoogleLoginIn({
6585
id: 0,
6686
name: this.state.name,

src/views/Auth/SingUp.jsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
1313
import { faChevronLeft } from '@fortawesome/free-solid-svg-icons/faChevronLeft';
1414
import { connect } from 'react-redux';
1515
import { singup } from '../../store/actions/user';
16+
import auth from '@react-native-firebase/auth';
1617
import BoxGlass from '../../components/BoxGlass';
1718

1819
class SingUp extends Component {
@@ -23,12 +24,28 @@ class SingUp extends Component {
2324
};
2425

2526
register = () => {
26-
this.props.onSingUp({
27-
id: 0,
28-
name: this.state.name,
29-
email: this.state.email,
30-
identy: null,
31-
});
27+
auth()
28+
.createUserWithEmailAndPassword(this.state.email, this.state.password)
29+
.then(() => {
30+
this.props.onSingUp({
31+
id: 0,
32+
name: this.state.name,
33+
email: this.state.email,
34+
identy: null,
35+
});
36+
console.log('User account created & signed in!');
37+
})
38+
.catch(error => {
39+
if (error.code === 'auth/email-already-in-use') {
40+
console.log('That email address is already in use!');
41+
}
42+
43+
if (error.code === 'auth/invalid-email') {
44+
console.log('That email address is invalid!');
45+
}
46+
47+
console.error(error);
48+
});
3249
};
3350

3451
render() {

0 commit comments

Comments
 (0)