add functions for login
This commit is contained in:
parent
abc9fcdb52
commit
beb804e38c
|
@ -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.';
|
||||
|
|
|
@ -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', {
|
||||
|
|
Reference in New Issue