add the signup process

This commit is contained in:
Andreas Zweili 2021-07-28 22:40:49 +02:00
parent 87c386bbd4
commit ba84e606c5
4 changed files with 42 additions and 4 deletions

View File

@ -57,6 +57,15 @@ export default {
this.formIsValid = false;
return;
}
if (this.mode === 'login') {
//
} else {
this.$store.dispatch('signup', {
email: this.email,
password: this.password
});
}
},
switchAuthMode() {
if (this.mode === 'login') {

View File

@ -1,3 +1,24 @@
//import getAPI from '../../../scripts/axios-api';
import getAuth from '../../../scripts/axios-auth';
export default {};
export default {
login() {},
async signup(context, payload) {
try {
const response = await getAuth.post('accounts:signUp', {
email: payload.email,
password: payload.password,
returnSecureToken: true
});
const responseData = response.data;
console.log(responseData);
context.commit('setUser', {
token: responseData.idToken,
userId: responseData.localId,
tokenExpiration: responseData.expiresIn
});
} catch (err) {
const error = new Error(err.message);
throw error;
}
}
};

View File

@ -5,7 +5,9 @@ import mutations from './mutations';
export default {
state() {
return {
userId: 'c3'
userId: null,
token: null,
tokenExpiration: null
};
},
actions,

View File

@ -1 +1,7 @@
export default {};
export default {
setUser(state, payload) {
state.token = payload.token;
state.userId = payload.userId;
state.tokenExpiration = payload.tokenExpiration;
}
};