mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-21 19:11:34 +08:00
[auth] implement firebase.auth.AuthSettings
This commit is contained in:
@@ -88,6 +88,20 @@ RCT_EXPORT_METHOD(removeIdTokenListener:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to determine whether app verification should be disabled for testing or not.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(
|
||||
setAppVerificationDisabledForTesting:
|
||||
(NSString *) appDisplayName
|
||||
disabled:
|
||||
(BOOL) disabled
|
||||
) {
|
||||
FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName];
|
||||
[FIRAuth authWithApp:firApp].settings.appVerificationDisabledForTesting = disabled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
70
src/modules/auth/AuthSettings.js
Normal file
70
src/modules/auth/AuthSettings.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import { getNativeModule } from '../../utils/native';
|
||||
import { isAndroid, isIOS } from '../../utils';
|
||||
|
||||
import type Auth from '.';
|
||||
|
||||
/**
|
||||
* Interface representing an Auth instance's settings, currently used
|
||||
* for enabling/disabling app verification for phone Auth testing. *
|
||||
*/
|
||||
export default class AuthSettings {
|
||||
_auth: Auth;
|
||||
|
||||
_appVerificationDisabledForTesting: boolean;
|
||||
|
||||
constructor(auth: Auth) {
|
||||
this._auth = auth;
|
||||
this._appVerificationDisabledForTesting = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to determine whether app verification should be disabled for testing or not.
|
||||
*
|
||||
* @platform iOS
|
||||
* @return {boolean}
|
||||
*/
|
||||
get appVerificationDisabledForTesting(): boolean {
|
||||
return this._appVerificationDisabledForTesting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to determine whether app verification should be disabled for testing or not.
|
||||
*
|
||||
* @platform iOS
|
||||
* @param disabled
|
||||
*/
|
||||
set appVerificationDisabledForTesting(disabled: boolean) {
|
||||
if (isIOS) {
|
||||
this._appVerificationDisabledForTesting = disabled;
|
||||
getNativeModule(this._auth).setAppVerificationDisabledForTesting(
|
||||
disabled
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The phone number and SMS code here must have been configured in the
|
||||
* Firebase Console (Authentication > Sign In Method > Phone).
|
||||
*
|
||||
* Calling this method a second time will overwrite the previously passed parameters.
|
||||
* Only one number can be configured at a given time.
|
||||
*
|
||||
* @platform Android
|
||||
* @param phoneNumber
|
||||
* @param smsCode
|
||||
* @return {*}
|
||||
*/
|
||||
setAutoRetrievedSmsCodeForPhoneNumber(
|
||||
phoneNumber: string,
|
||||
smsCode: string
|
||||
): Promise<null> {
|
||||
if (isAndroid) {
|
||||
return getNativeModule(this._auth).setAutoRetrievedSmsCodeForPhoneNumber(
|
||||
phoneNumber,
|
||||
smsCode
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import { getNativeModule } from '../../utils/native';
|
||||
import INTERNALS from '../../utils/internals';
|
||||
import ConfirmationResult from './phone/ConfirmationResult';
|
||||
import PhoneAuthListener from './phone/PhoneAuthListener';
|
||||
import AuthSettings from './AuthSettings';
|
||||
|
||||
// providers
|
||||
import EmailAuthProvider from './providers/EmailAuthProvider';
|
||||
@@ -49,6 +50,8 @@ export default class Auth extends ModuleBase {
|
||||
|
||||
_languageCode: string;
|
||||
|
||||
_settings: AuthSettings | null;
|
||||
|
||||
_user: User | null;
|
||||
|
||||
constructor(app: App) {
|
||||
@@ -59,7 +62,9 @@ export default class Auth extends ModuleBase {
|
||||
hasCustomUrlSupport: false,
|
||||
namespace: NAMESPACE,
|
||||
});
|
||||
|
||||
this._user = null;
|
||||
this._settings = null;
|
||||
this._authResult = false;
|
||||
this._languageCode =
|
||||
getNativeModule(this).APP_LANGUAGE[app._name] ||
|
||||
@@ -522,15 +527,38 @@ export default class Auth extends ModuleBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the language for the auth module
|
||||
* Sets the language for the auth module.
|
||||
*
|
||||
* @param code
|
||||
* @returns {*}
|
||||
*/
|
||||
set languageCode(code: string) {
|
||||
this._languageCode = code;
|
||||
getNativeModule(this).setLanguageCode(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* The language for the auth module.
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
get languageCode(): string {
|
||||
return this._languageCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current Auth instance's settings. This is used to edit/read configuration
|
||||
* related options like app verification mode for phone authentication.
|
||||
*
|
||||
* @return {AuthSettings}
|
||||
*/
|
||||
get settings(): AuthSettings {
|
||||
if (!this._settings) {
|
||||
// lazy initialize
|
||||
this._settings = new AuthSettings(this);
|
||||
}
|
||||
return this._settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently signed in user
|
||||
* @return {Promise}
|
||||
@@ -539,10 +567,6 @@ export default class Auth extends ModuleBase {
|
||||
return this._user;
|
||||
}
|
||||
|
||||
get languageCode(): string {
|
||||
return this._languageCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* KNOWN UNSUPPORTED METHODS
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user