@@ -14,7 +14,7 @@ import {
1414} from "react-native"
1515
1616import AntDesign from "react-native-vector-icons/AntDesign" ;
17- import { GoogleSignin , GoogleSigninButton , statusCodes } from '@react-native-community/google-signin' ;
17+ import { GoogleSignin , statusCodes } from '@react-native-community/google-signin' ;
1818
1919const Dev_Height = Dimensions . get ( 'screen' ) . height
2020const Dev_Width = Dimensions . get ( 'screen' ) . width
@@ -29,24 +29,21 @@ export default class LoginScreen extends React.Component{
2929 loggedIn :false ,
3030 photo :""
3131 }
32+ this . isSignedIn ( )
33+ }
3234
35+ componentDidMount ( ) {
3336 GoogleSignin . configure ( {
3437 scopes : [ "https://www.googleapis.com/auth/userinfo.profile" ] ,
35- webClientId : '****** ' ,
38+ webClientId : '106054659932-bo6jk5s6eukeib2pf7d8r6n7er6ofn1b.apps.googleusercontent.com ' ,
3639 offlineAccess : true , // if you want to access Google API on behalf of the user FROM YOUR SERVER
37- forceCodeForRefreshToken : true , // [Android] related to `serverAuthCode`, read the docs link below *.
3840 } ) ;
39-
40- this . isSignedIn ( )
41-
42-
4341 }
4442
4543 signIn = async ( ) => {
4644 try {
4745 await GoogleSignin . hasPlayServices ( ) ;
4846 const userInfo = await GoogleSignin . signIn ( ) ;
49-
5047 this . setState ( { userInfoDetails : userInfo } )
5148 this . setState ( { userInfoDetails : this . state . userInfoDetails } )
5249 this . setState ( { name : this . state . userInfoDetails . user . name } )
@@ -57,13 +54,9 @@ export default class LoginScreen extends React.Component{
5754 this . setState ( { loggedIn : this . state . loggedIn } )
5855
5956 } catch ( error ) {
60- console . log ( 'Message' , error . message ) ;
6157 if ( error . code === statusCodes . SIGN_IN_CANCELLED ) {
62- console . log ( 'User Cancelled the Login Flow' ) ;
6358 } else if ( error . code === statusCodes . IN_PROGRESS ) {
64- console . log ( 'Signing In' ) ;
6559 } else if ( error . code === statusCodes . PLAY_SERVICES_NOT_AVAILABLE ) {
66- console . log ( 'Play Services Not Available or Outdated' ) ;
6760 } else {
6861 console . log ( error . message ) ;
6962 }
@@ -78,10 +71,10 @@ export default class LoginScreen extends React.Component{
7871
7972 isSignedIn = async ( ) => {
8073 const isSignedIn = await GoogleSignin . isSignedIn ( ) ;
81- if ( ! ! isSignedIn ) {
74+ if ( isSignedIn ) {
8275 this . getCurrentUserInfo ( )
8376 } else {
84- console . log ( 'Please Login' )
77+ this . signIn ( )
8578 }
8679 } ;
8780
@@ -90,18 +83,17 @@ export default class LoginScreen extends React.Component{
9083 const userInfo = await GoogleSignin . signInSilently ( ) ;
9184 this . setState ( { userInfoDetails : userInfo } )
9285 this . setState ( { userInfoDetails : this . state . userInfoDetails } )
86+ this . setState ( { name : this . state . userInfoDetails . user . name } )
9387 this . setState ( { name : this . state . name } )
9488 this . setState ( { photo : this . state . userInfoDetails . user . photo } )
9589 this . setState ( { photo : this . state . photo } )
9690 this . setState ( { loggedIn : true } )
9791 this . setState ( { loggedIn : this . state . loggedIn } )
9892
99-
10093 } catch ( error ) {
10194 if ( error . code === statusCodes . SIGN_IN_REQUIRED ) {
102- console . log ( 'User has not signed in yet' ) ;
95+ this . signIn ( )
10396 } else {
104- console . log ( "Something went wrong. Unable to get user's info" ) ;
10597 }
10698 }
10799 } ;
@@ -126,7 +118,7 @@ export default class LoginScreen extends React.Component{
126118
127119 < View style = { styles . sign_up_google_View } >
128120 { ! this . state . loggedIn ?
129- < TouchableOpacity style = { styles . sign_up_button } onPress = { this . signIn } >
121+ < TouchableOpacity style = { styles . sign_up_button } onPress = { this . isSignedIn } >
130122 < AntDesign name = "google" color = "#FFF" size = { 24 } />
131123 < Text style = { styles . sign_up_google } > Sign Up With Google </ Text >
132124 </ TouchableOpacity > :
@@ -153,7 +145,6 @@ const styles=StyleSheet.create({
153145 design_view :{
154146 height :"40%" ,
155147 width :"100%" ,
156- backgroundColor :"#000" ,
157148 alignItems :"center"
158149 } ,
159150 design_image :{
0 commit comments