use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.
the class FirebaseAuthentication method handleSuccessfulSignIn.
public void handleSuccessfulSignIn(final PluginCall call, AuthCredential credential, String idToken, String nonce) {
boolean skipNativeAuth = this.config.getSkipNativeAuth();
if (skipNativeAuth) {
JSObject signInResult = FirebaseAuthenticationHelper.createSignInResult(null, credential, idToken, nonce);
call.resolve(signInResult);
return;
}
firebaseAuthInstance.signInWithCredential(credential).addOnCompleteListener(plugin.getActivity(), new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(FirebaseAuthenticationPlugin.TAG, "signInWithCredential succeeded.");
FirebaseUser user = getCurrentUser();
JSObject signInResult = FirebaseAuthenticationHelper.createSignInResult(user, credential, idToken, nonce);
call.resolve(signInResult);
} else {
Log.e(FirebaseAuthenticationPlugin.TAG, "signInWithCredential failed.", task.getException());
call.reject(ERROR_SIGN_IN_FAILED);
}
}
}).addOnFailureListener(plugin.getActivity(), new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(FirebaseAuthenticationPlugin.TAG, "signInWithCredential failed.", exception);
call.reject(ERROR_SIGN_IN_FAILED);
}
});
}
use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.
the class FirebaseAuthenticationHelper method createUserResult.
public static JSObject createUserResult(FirebaseUser user) {
if (user == null) {
return null;
}
JSObject result = new JSObject();
result.put("displayName", user.getDisplayName());
result.put("email", user.getEmail());
result.put("emailVerified", user.isEmailVerified());
result.put("isAnonymous", user.isAnonymous());
result.put("phoneNumber", user.getPhoneNumber());
result.put("photoUrl", user.getPhotoUrl());
result.put("providerId", user.getProviderId());
result.put("tenantId", user.getTenantId());
result.put("uid", user.getUid());
return result;
}
use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.
the class FirebaseAuthenticationPlugin method getIdToken.
@PluginMethod
public void getIdToken(PluginCall call) {
Boolean forceRefresh = call.getBoolean("forceRefresh", false);
implementation.getIdToken(forceRefresh, new GetIdTokenResultCallback() {
@Override
public void success(String token) {
JSObject result = new JSObject();
result.put("token", token);
call.resolve(result);
}
@Override
public void error(String message) {
call.reject(message);
}
});
}
use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.
the class FirebaseAuthenticationPlugin method getCurrentUser.
@PluginMethod
public void getCurrentUser(PluginCall call) {
FirebaseUser user = implementation.getCurrentUser();
JSObject userResult = FirebaseAuthenticationHelper.createUserResult(user);
JSObject result = new JSObject();
result.put("user", userResult);
call.resolve(result);
}
use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.
the class FirebaseAuthenticationPlugin method updateAuthState.
private void updateAuthState() {
FirebaseUser user = implementation.getCurrentUser();
JSObject userResult = FirebaseAuthenticationHelper.createUserResult(user);
JSObject result = new JSObject();
result.put("user", userResult);
notifyListeners(AUTH_STATE_CHANGE_EVENT, result);
}
Aggregations