[android] link/linkPassword

This commit is contained in:
Salakar 2017-03-16 12:19:34 +00:00
parent afece365e4
commit b6c406c7aa
3 changed files with 53 additions and 43 deletions

View File

@ -357,53 +357,66 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
} }
} }
/**
// ----------------------- CLEAN ME ----------------------------------------------------- * link
// ----------------------- CLEAN ME ----------------------------------------------------- *
// ----------------------- CLEAN ME ----------------------------------------------------- * @param provider
// ----------------------- CLEAN ME ----------------------------------------------------- * @param authToken
// ----------------------- CLEAN ME ----------------------------------------------------- * @param authSecret
// ----------------------- CLEAN ME ----------------------------------------------------- * @param promise
// ----------------------- CLEAN ME ----------------------------------------------------- */
// ----------------------- CLEAN ME -----------------------------------------------------
// ----------------------- CLEAN ME -----------------------------------------------------
@ReactMethod @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(); FirebaseUser user = mAuth.getCurrentUser();
Log.d(TAG, "linkPassword");
if (user != null) { if (user != null) {
AuthCredential credential = EmailAuthProvider.getCredential(email, password); AuthCredential credential = EmailAuthProvider.getCredential(email, password);
user user.linkWithCredential(credential)
.linkWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() { .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override @Override
public void onComplete(@NonNull Task<AuthResult> task) { public void onComplete(@NonNull Task<AuthResult> task) {
try { if (task.isSuccessful()) {
if (task.isSuccessful()) { Log.d(TAG, "linkPassword:onComplete:success");
Log.d(TAG, "user linked with password credential"); promiseWithUser(mAuth.getCurrentUser(), promise);
userCallback(mAuth.getCurrentUser(), callback); } else {
} else { Exception exception = task.getException();
userErrorCallback(task, callback); WritableMap error = authExceptionToMap(exception);
} Log.e(TAG, "linkPassword:onComplete:failure", exception);
} catch (Exception ex) { promise.reject(error.getString("code"), error.getString("message"), exception);
userExceptionCallback(ex, callback);
} }
} }
}); });
} else { } else {
callbackNoUser(callback, true); promiseNoUser(promise, true);
} }
} }
@ReactMethod
public void link(final String provider, final String authToken, final String authSecret, final Callback callback) { // ----------------------- CLEAN ME -----------------------------------------------------
if (provider.equals("password")) { // ----------------------- CLEAN ME -----------------------------------------------------
linkPassword(authToken, authSecret, callback); // ----------------------- CLEAN ME -----------------------------------------------------
} else // ----------------------- CLEAN ME -----------------------------------------------------
// TODO other providers // ----------------------- CLEAN ME -----------------------------------------------------
Utils.todoNote(TAG, "linkWithProvider", callback); // ----------------------- CLEAN ME -----------------------------------------------------
} // ----------------------- CLEAN ME -----------------------------------------------------
// ----------------------- CLEAN ME -----------------------------------------------------
// ----------------------- CLEAN ME -----------------------------------------------------
@ReactMethod @ReactMethod
public void reauthenticate(final String provider, final String authToken, final String authSecret, final Callback callback) { public void reauthenticate(final String provider, final String authToken, final String authSecret, final Callback callback) {

View File

@ -4,7 +4,6 @@ import { NativeModules, NativeEventEmitter } from 'react-native';
import User from './user'; import User from './user';
import { Base } from './../base'; import { Base } from './../base';
import EmailAuthProvider from './Email'; import EmailAuthProvider from './Email';
import { promisify } from './../../utils';
const FirebaseAuth = NativeModules.RNFirebaseAuth; const FirebaseAuth = NativeModules.RNFirebaseAuth;
const FirebaseAuthEvt = new NativeEventEmitter(FirebaseAuth); const FirebaseAuthEvt = new NativeEventEmitter(FirebaseAuth);

View File

@ -4,7 +4,6 @@ import { promisify } from './../../utils';
const FirebaseAuth = NativeModules.RNFirebaseAuth; const FirebaseAuth = NativeModules.RNFirebaseAuth;
// TODO refreshToken property // TODO refreshToken property
// TODO reload() method
/** /**
* @url https://firebase.google.com/docs/reference/js/firebase.User * @url https://firebase.google.com/docs/reference/js/firebase.User
@ -112,6 +111,14 @@ export default class User {
return this._auth._interceptUserValue(FirebaseAuth.delete()); 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 * Reload the current user
* @return {Promise} * @return {Promise}
@ -141,15 +148,6 @@ export default class User {
return promisify('getToken', FirebaseAuth, 'auth/')(); 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 * Update the current user's email
* @param {string} email The user's _new_ email * @param {string} email The user's _new_ email