mirror of
https://github.com/vale981/accounts-ui
synced 2025-03-05 09:51:40 -05:00
Merge pull request #91 from comus/patch-1
Fixed: localStorage not defined in server side
This commit is contained in:
commit
7edc744db5
4 changed files with 18 additions and 13 deletions
|
@ -80,11 +80,12 @@ export function validatePassword(password = '', showMessage, clearMessage){
|
|||
}
|
||||
};
|
||||
|
||||
export function validateUsername(username, showMessage, clearMessage) {
|
||||
export function validateUsername(username, showMessage, clearMessage, formState) {
|
||||
if ( username ) {
|
||||
return true;
|
||||
} else {
|
||||
showMessage(T9n.get("error.usernameRequired"), 'warning', false, 'username');
|
||||
const fieldName = (passwordSignupFields() === 'USERNAME_ONLY' || formState === STATES.SIGN_UP) ? 'username' : 'usernameOrEmail';
|
||||
showMessage(T9n.get("error.usernameRequired"), 'warning', false, fieldName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ export class Field extends React.Component {
|
|||
triggerUpdate() {
|
||||
// Trigger an onChange on inital load, to support browser prefilled values.
|
||||
const { onChange } = this.props;
|
||||
if (this.input && this.input.value) {
|
||||
if (this.input && onChange) {
|
||||
onChange({ target: { value: this.input.value } });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ export class Form extends React.Component {
|
|||
ref={(ref) => this.form = ref}
|
||||
className={[className, ready ? "ready" : null].join(' ')}
|
||||
className="accounts-ui"
|
||||
novalidate
|
||||
noValidate
|
||||
>
|
||||
<Accounts.ui.Fields fields={ fields } />
|
||||
<Accounts.ui.Buttons buttons={ buttons } />
|
||||
|
|
|
@ -92,6 +92,7 @@ export class LoginForm extends Tracker.Component {
|
|||
}
|
||||
|
||||
validateField(field, value) {
|
||||
const { formState } = this.state;
|
||||
switch(field) {
|
||||
case 'email':
|
||||
return validateEmail(value,
|
||||
|
@ -107,6 +108,7 @@ export class LoginForm extends Tracker.Component {
|
|||
return validateUsername(value,
|
||||
this.showMessage.bind(this),
|
||||
this.clearMessage.bind(this),
|
||||
formState,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -425,7 +427,7 @@ export class LoginForm extends Tracker.Component {
|
|||
setDefaultFieldValues(defaults) {
|
||||
if (typeof defaults !== 'object') {
|
||||
throw new Error('Argument to setDefaultFieldValues is not of type object');
|
||||
} else if (localStorage) {
|
||||
} else if (typeof localStorage !== 'undefined' && localStorage) {
|
||||
localStorage.setItem('accounts_ui', JSON.stringify({
|
||||
passwordSignupFields: passwordSignupFields(),
|
||||
...this.getDefaultFieldValues(),
|
||||
|
@ -438,7 +440,7 @@ export class LoginForm extends Tracker.Component {
|
|||
* Helper to get field values when switching states in the form.
|
||||
*/
|
||||
getDefaultFieldValues() {
|
||||
if (localStorage) {
|
||||
if (typeof localStorage !== 'undefined' && localStorage) {
|
||||
const defaultFieldValues = JSON.parse(localStorage.getItem('accounts_ui') || null);
|
||||
if (defaultFieldValues
|
||||
&& defaultFieldValues.passwordSignupFields === passwordSignupFields()) {
|
||||
|
@ -451,7 +453,7 @@ export class LoginForm extends Tracker.Component {
|
|||
* Helper to clear field values when signing in, up or out.
|
||||
*/
|
||||
clearDefaultFieldValues() {
|
||||
if (localStorage) {
|
||||
if (typeof localStorage !== 'undefined' && localStorage) {
|
||||
localStorage.removeItem('accounts_ui');
|
||||
}
|
||||
}
|
||||
|
@ -906,12 +908,14 @@ export class LoginForm extends Tracker.Component {
|
|||
|
||||
componentWillMount() {
|
||||
// XXX Check for backwards compatibility.
|
||||
const container = document.createElement('div');
|
||||
ReactDOM.render(<Accounts.ui.Field message="test" />, container);
|
||||
if (container.getElementsByClassName('message').length == 0) {
|
||||
// Found backwards compatibility issue with 1.3.x
|
||||
console.warn(`Implementations of Accounts.ui.Field must render message in v1.2.11.
|
||||
https://github.com/studiointeract/accounts-ui/#deprecations`);
|
||||
if (Meteor.isClient) {
|
||||
const container = document.createElement('div');
|
||||
ReactDOM.render(<Accounts.ui.Field message="test" />, container);
|
||||
if (container.getElementsByClassName('message').length == 0) {
|
||||
// Found backwards compatibility issue with 1.3.x
|
||||
console.warn(`Implementations of Accounts.ui.Field must render message in v1.2.11.
|
||||
https://github.com/studiointeract/accounts-ui/#deprecations`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue