in my react native app I want to let users sign in with google, for this I'm using firebase. In react native side I get user token id and then send it to the backend where i use google client api to verify token id but I never get to validate it as it returns false.
On react native side:
import auth from '@react-native-firebase/auth';
import { GoogleSignin } from '@react-native-google-signin/google-signin';
useEffect(() => {
GoogleSignin.configure({
webClientId: 'XXX---.apps.googleusercontent.com',
});
}, []);
const onGoogleButtonPress = async () =>
{
try
{
//Get the users ID token
const { idToken } = await GoogleSignin.signIn();
console.log('idToken', idToken);
// Create a Google credential with the token
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
console.log('googleCredential', googleCredential);
// Sign-in the user with the credential
let signWithCredential = await auth().signInWithCredential(googleCredential);
let iddd = await auth().currentUser.getIdToken();
console.log('iddd',iddd);
let url = env.BASE_URL+'/api/auth/sign-in-with-google';
let payload = { token_id : iddd };
let response = await http.post(url, payload);
}
catch (error)
{
console.log(error);
throw error;
}
};
On my PHP backend side (laravel).
public function signInWithGoogle(Request $request)
{
$token_id = $request->input('token_id');
$client = new Google_Client(['client_id' => 'XXX---.apps.googleusercontent.com']);
try {
$payload = $client->verifyIdToken($token_id);
//$payload returns false and I get Invalid token message, no error message or catched error...
if (!$payload) {
return response()->json(['error' => 'Invalid token', 'payload' => $payload], 401);
}
$userid = $payload['sub'];
$email = $payload['email'];
$name = $payload['name'];
// Your logic here...
return response()->json(['message' => 'Success']); // or return your desired data
} catch (Exception $e) {
return response()->json(['error' => 'Invalid token: ' . $e->getMessage()], 401);
}
return response()->json([
'results' => $results,
]);
}
PROBLEM: payload always returns false for some reason
Hello and thanks for asking,
this bug tracker is reserved for bugs, while this seems like a usage question.
With that, I'm going to close this.
Thank you 🙂
in my react native app I want to let users sign in with google, for this I'm using firebase. In react native side I get user token id and then send it to the backend where i use google client api to verify token id but I never get to validate it as it returns false.
On react native side:
On my PHP backend side (laravel).
PROBLEM: payload always returns false for some reason