I need help. i am new to Ionic Vue, i at an intermediate level in PHP. I am trying to learn how i can implement a simple project. I AM TRYING TO MAKE IT SIMPLE
- Create a login page,
<form @submit.prevent="submitForm">
<ion-input type="text" placeholder="Username" v-model="username" required />
<br />
<ion-input type="password" placeholder="Password" v-model="password" required />
<br />
<ion-button type="submit" expand="block" shape="round">Login</ion-button>
<button class="forgot"> Forgot Password? </button>
</form>
- after a user clicks the submit button, then call an API to verify the details with my MySQL server
data() {
return {
username: null,
password: null,
serverResponse: []
};
},
methods: {
submitForm() {
this.AuthenticateWithServer([this.username, this.password]);
},
async AuthenticateWithServer(inputs) {
try {
const result = await axios.get(`https://127.0.0.1/api/authenticate.php?phone=${inputs[0]}&password=${inputs[1]}`);
this.serverResponse = result.data;
switch(this.serverResponse['result']){
case 200:
this.loginSuccessful();
break;
case 400:
this.showToast("Oops! it seems you have entered wrong username or password");
break;
case 500:
this.showToast("Oops! please provide your details to login");
break;
}
} catch(e) {
this.showToast("Seems you are not connected to Internet");
}
},
- if the response is “200”, I want to redirect to another page, say, dashboard. so on the in loginSuccessful(), i am calling this code but its not working
loginSuccessful() {
this.$router.push('/pages/dashboard');
},
but it’s redirecting even if the response is 200…
Please help, how can i do it better
1 post - 1 participant