My approach to verifying whether the channel route input requires a PIN code involves using router.beforeEach as outlined below:
router.beforeEach((to, from, next) => {
if(to.path == '/') {
next();
}else {
store.dispatch('checkChannelhasPin', to.params.id).then(()=>{
console.log(store.getters);
console.log(store.getters.ispin);
setTimeout(() => {
console.log(store.getters.ispin);
}, 500);
})
}
}
Upon console.log
evaluation, three results are observed:
https://i.sstatic.net/flARp.png
The challenge faced is the inability to retrieve stateispin post 'checkChannelhasPin' verification.
The action plan is depicted as follows:
import axios from 'axios';
import setChannelAuthToken from '../../utils/setChannelAuthToken';
import {
CHECK_CHANNEL_HASPIN
} from '../typeName';
const state = {
ispin: true,
}
const getters = {
ispin: (state) => state.ispin
};
const actions = {
async checkChannelhasPin({commit}, params) {
axios.post(
window.home+'/json/channel/checkAuth',
{
channel_id:params
}
).then((response) => {
let payload = response.data.ispin;
commit(CHECK_CHANNEL_HASPIN, payload);
}).catch( (error) => {
console.log(error);
});
}
}
const mutations = {
CHECK_CHANNEL_HASPIN: (state, payload) => (state.ispin = payload)
};
export default {
state,
getters,
actions,
mutations
};
Your suggestions and advice would be highly appreciated. Many thanks in advance.