add functions for login

This commit is contained in:
Andreas Zweili 2021-07-28 22:58:02 +02:00
parent abc9fcdb52
commit beb804e38c
2 changed files with 26 additions and 6 deletions

View File

@ -69,14 +69,16 @@ export default {
return;
}
this.isLoading = true;
const actionPayload = {
email: this.email,
password: this.password
};
try {
if (this.mode === 'login') {
//
await this.$store.dispatch('login', actionPayload);
} else {
await this.$store.dispatch('signup', {
email: this.email,
password: this.password
});
await this.$store.dispatch('signup', actionPayload);
}
} catch (error) {
this.error = error.message || 'Failed to authenticate, try later.';

View File

@ -1,7 +1,25 @@
import getAuth from '../../../scripts/axios-auth';
export default {
login() {},
async login(context, payload) {
try {
const response = await getAuth.post('accounts:signInWithPassword', {
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;
}
},
async signup(context, payload) {
try {
const response = await getAuth.post('accounts:signUp', {