I'm going straight to the point here. I'm doing an authentication on the login page, after clicking the login page it redirects me to a product's component and on that product's component, I do an HTTP request to get all the products. However, after logging in and redirecting on the products page the product's component seems it can't run my HTTP request on the created() lifecycle hooks. Is this a normal behaviour?
Here's my code:
LOGIN:
export default{
data(){
return {
email: '',
password: ''
}
},
methods:{
login(){
var data = {
client_id: 2,
client_secret: 'TOKEN_HERE,
grant_type: 'password',
username: this.email,
password: this.password
}
this.$http.post("oauth/token", data).then(response => {
this.$auth.setToken(response.body.access_token, response.body.expires_in + Date.now())
this.$router.push('/products')
})
}
}
PRODUCTS.VUE
import Products from './product/Products.vue'
export default {
components: {
'my-products' : Products
},
created(){
this.$http.get('api/products')
.then(response => {
alert("products from feed");
this.products = response.body
})
}
}
after redirecting to products.vue created lifecycle hook, it can't run my http request.
Thanks in advance.
createdhook is not triggering?products componentusing this.$router.push('/products').. after the redirection thecreated()lifecyclye hook can't run myhttp request.. it gives me error on my consoleuncaught (in promise)this.$http.get('api/products') .then(response => { alert("products from feed"); this.products = response.body }, err => console.log('error is:', err));can you paste the error here?Unauthenticated.. however I am 100% sure I am authenticated... when I refresh the page it shows me all the products... however, the initial load of the page afterthis.$router.pushgives me unauthorized error