S
methods: {
signup() {
const { name, email, password } = this;
const record = {
name, email, password,
URL: '',
description: ''
};
const store = {
name, email, password,
id: '',
photoURL: '',
description: '',
firebaseDocumentId: ''
};
const messages = {
'auth/weak-password': 'Password too weak'
};
const save = () => (
Object
.keys(store)
.forEach((key) => localStorage.setItem(key, store[key]))
);
const toast = (message) => this.$toasted.show(message).goAway(3000);
const flush = () => (
[ 'name', 'email', 'password' ].forEach((key) => this[key] = '')
);
const toChat = () => this.$router.push('/chat');
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(({ user: { uid: id } }) => store.id = id)
.then(() => firebase.firestore().collection('users').add(record))
.then(({ id }) => store.firebaseDocumentId = id)
.then(() => save())
.then(() => flush())
.then(() => toChat())
.catch(({ code, message }) => toast(messages[code] || message));
}
}
