This commit is contained in:
2025-12-12 10:42:06 +00:00
parent 089cb14998
commit 661bbaab46
5 changed files with 155 additions and 92 deletions

View File

@@ -69,7 +69,6 @@ public class CriarContaActivity extends AppCompatActivity {
credentialManager = CredentialManager.create(this);
loginButton2.setOnClickListener(v -> criarConta());
googleButton2.setOnClickListener(v -> signInWithGoogle());
}
private void criarConta() {
@@ -176,46 +175,6 @@ public class CriarContaActivity extends AppCompatActivity {
return true;
}
private void signInWithGoogle() {
String webClientId = getString(R.string.default_web_client_id);
if (webClientId.equals("YOUR_WEB_CLIENT_ID_HERE")) {
Toast.makeText(this, "Por favor, configure o Web Client ID no Firebase Console.", Toast.LENGTH_LONG).show();
return;
}
GetGoogleIdOption googleIdOption = new GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(false)
.setServerClientId(webClientId)
.build();
GetCredentialRequest request = new GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build();
toggleLoading(true);
credentialManager.getCredential(
this,
request,
null
);
}
private void handleGoogleSignInResult(GetCredentialResponse result) {
Credential credential = result.getCredential();
if (credential instanceof CustomCredential) {
CustomCredential customCredential = (CustomCredential) credential;
if (GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL.equals(customCredential.getType())) {
GoogleIdTokenCredential googleIdTokenCredential = GoogleIdTokenCredential
.createFrom(customCredential.getData());
String idToken = googleIdTokenCredential.getIdToken();
firebaseAuthWithGoogle(idToken);
}
}
}
private void firebaseAuthWithGoogle(String idToken) {
AuthCredential credential = GoogleAuthProvider.getCredential(idToken, null);
firebaseAuth.signInWithCredential(credential)