Search in sources :

Example 26 with JSObject

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);
        }
    });
}
Also used : OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) Task(com.google.android.gms.tasks.Task) NonNull(androidx.annotation.NonNull) JSObject(com.getcapacitor.JSObject) FirebaseUser(com.google.firebase.auth.FirebaseUser) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 27 with JSObject

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;
}
Also used : JSObject(com.getcapacitor.JSObject)

Example 28 with JSObject

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);
        }
    });
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 29 with JSObject

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);
}
Also used : JSObject(com.getcapacitor.JSObject) FirebaseUser(com.google.firebase.auth.FirebaseUser) PluginMethod(com.getcapacitor.PluginMethod)

Example 30 with JSObject

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);
}
Also used : JSObject(com.getcapacitor.JSObject) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Aggregations

JSObject (com.getcapacitor.JSObject)169 PluginMethod (com.getcapacitor.PluginMethod)93 JSONException (org.json.JSONException)28 JSONObject (org.json.JSONObject)20 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)16 JSArray (com.getcapacitor.JSArray)14 Radar (io.radar.sdk.Radar)12 Uri (android.net.Uri)11 Location (android.location.Location)9 JSONArray (org.json.JSONArray)7 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ParseException (java.text.ParseException)5 Intent (android.content.Intent)4 FirebaseUser (com.google.firebase.auth.FirebaseUser)4 Gson (com.google.gson.Gson)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4