[analytics] Add additional validation

This commit is contained in:
Chris Bianca 2018-03-22 08:46:00 +00:00
parent 213f03737b
commit e3ea0d3fc7
1 changed files with 19 additions and 3 deletions

View File

@ -122,7 +122,12 @@ export default class Analytics extends ModuleBase {
* Sets the user ID property.
* @param id
*/
setUserId(id: string): void {
setUserId(id: string | null): void {
if (id !== null && !isString(id)) {
throw new Error(
'analytics.setUserId(): The supplied userId must be a string value or null.'
);
}
getNativeModule(this).setUserId(id);
}
@ -131,17 +136,28 @@ export default class Analytics extends ModuleBase {
* @param name
* @param value
*/
setUserProperty(name: string, value: string): void {
setUserProperty(name: string, value: string | null): void {
if (value !== null && !isString(value)) {
throw new Error(
'analytics.setUserProperty(): The supplied property must be a string value or null.'
);
}
getNativeModule(this).setUserProperty(name, value);
}
/**
* Sets a user property to a given value.
* Sets multiple user properties to the supplied values.
* @RNFirebaseSpecific
* @param object
*/
setUserProperties(object: Object): void {
Object.keys(object).forEach(property => {
const value = object[property];
if (value !== null && !isString(value)) {
throw new Error(
`analytics.setUserProperties(): The property with name '${property}' must be a string value or null.`
);
}
getNativeModule(this).setUserProperty(property, object[property]);
});
}