diff --git a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java index 5fed18e9..e8814085 100644 --- a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java +++ b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java @@ -357,53 +357,66 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule { } } - - // ----------------------- CLEAN ME ----------------------------------------------------- - // ----------------------- CLEAN ME ----------------------------------------------------- - // ----------------------- CLEAN ME ----------------------------------------------------- - // ----------------------- CLEAN ME ----------------------------------------------------- - // ----------------------- CLEAN ME ----------------------------------------------------- - // ----------------------- CLEAN ME ----------------------------------------------------- - // ----------------------- CLEAN ME ----------------------------------------------------- - // ----------------------- CLEAN ME ----------------------------------------------------- - // ----------------------- CLEAN ME ----------------------------------------------------- - + /** + * link + * + * @param provider + * @param authToken + * @param authSecret + * @param promise + */ @ReactMethod - public void linkPassword(final String email, final String password, final Callback callback) { + public void link(final String provider, final String authToken, final String authSecret, final Promise promise) { + if (provider.equals("password")) { + linkPassword(authToken, authSecret, promise); + } else + promise.reject("auth/todo", "Method currently not implemented."); + } + + /** + * linkPassword + * + * @param email + * @param password + * @param promise + */ + @ReactMethod + public void linkPassword(final String email, final String password, final Promise promise) { FirebaseUser user = mAuth.getCurrentUser(); + Log.d(TAG, "linkPassword"); if (user != null) { AuthCredential credential = EmailAuthProvider.getCredential(email, password); - user - .linkWithCredential(credential) + user.linkWithCredential(credential) .addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { - try { - if (task.isSuccessful()) { - Log.d(TAG, "user linked with password credential"); - userCallback(mAuth.getCurrentUser(), callback); - } else { - userErrorCallback(task, callback); - } - } catch (Exception ex) { - userExceptionCallback(ex, callback); + if (task.isSuccessful()) { + Log.d(TAG, "linkPassword:onComplete:success"); + promiseWithUser(mAuth.getCurrentUser(), promise); + } else { + Exception exception = task.getException(); + WritableMap error = authExceptionToMap(exception); + Log.e(TAG, "linkPassword:onComplete:failure", exception); + promise.reject(error.getString("code"), error.getString("message"), exception); } } }); } else { - callbackNoUser(callback, true); + promiseNoUser(promise, true); } } - @ReactMethod - public void link(final String provider, final String authToken, final String authSecret, final Callback callback) { - if (provider.equals("password")) { - linkPassword(authToken, authSecret, callback); - } else - // TODO other providers - Utils.todoNote(TAG, "linkWithProvider", callback); - } + + // ----------------------- CLEAN ME ----------------------------------------------------- + // ----------------------- CLEAN ME ----------------------------------------------------- + // ----------------------- CLEAN ME ----------------------------------------------------- + // ----------------------- CLEAN ME ----------------------------------------------------- + // ----------------------- CLEAN ME ----------------------------------------------------- + // ----------------------- CLEAN ME ----------------------------------------------------- + // ----------------------- CLEAN ME ----------------------------------------------------- + // ----------------------- CLEAN ME ----------------------------------------------------- + // ----------------------- CLEAN ME ----------------------------------------------------- @ReactMethod public void reauthenticate(final String provider, final String authToken, final String authSecret, final Callback callback) { diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index 60780100..f8f6fe4c 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -4,7 +4,6 @@ import { NativeModules, NativeEventEmitter } from 'react-native'; import User from './user'; import { Base } from './../base'; import EmailAuthProvider from './Email'; -import { promisify } from './../../utils'; const FirebaseAuth = NativeModules.RNFirebaseAuth; const FirebaseAuthEvt = new NativeEventEmitter(FirebaseAuth); diff --git a/lib/modules/auth/user.js b/lib/modules/auth/user.js index cff97aa5..724b7ae1 100644 --- a/lib/modules/auth/user.js +++ b/lib/modules/auth/user.js @@ -4,7 +4,6 @@ import { promisify } from './../../utils'; const FirebaseAuth = NativeModules.RNFirebaseAuth; // TODO refreshToken property -// TODO reload() method /** * @url https://firebase.google.com/docs/reference/js/firebase.User @@ -112,6 +111,14 @@ export default class User { return this._auth._interceptUserValue(FirebaseAuth.delete()); } + /** + * + * @param credential + */ + link(credential: CredentialType) { + return this._auth._interceptUserValue(FirebaseAuth.link(credential.provider, credential.token, credential.secret)); + } + /** * Reload the current user * @return {Promise} @@ -141,15 +148,6 @@ export default class User { return promisify('getToken', FirebaseAuth, 'auth/')(); } - /** - * - * @param credential - */ - link(credential: CredentialType) { - return promisify('link', FirebaseAuth, 'auth/')(credential.provider, credential.token, credential.secret); - } - - /** * Update the current user's email * @param {string} email The user's _new_ email