@@ -19,29 +19,40 @@ import { fetchUser, singup } from '../../store/actions/user';
1919import auth from '@react-native-firebase/auth' ;
2020import { GoogleSignin } from '@react-native-google-signin/google-signin' ;
2121
22- // GoogleSignin.configure({
23- // webClientId: '897362002662-kihdbmlmur6gsj5s3mi7m9o808j0m5s4.apps.googleusercontent.com',
24- // offlineAccess: true,
25- // });
26-
2722class 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 ,
0 commit comments