The problem is flowbite's js(like menu or dropdowns) do not work when vue router has async/await things.
So when i remove await
keyword everything works fine, but the thing is i need that async/await to authenticate a user. The js that placed in vue components works fine always. Tailwind and flowbite was installed accorded to official flowbite documentation/ Also i've noticed that when js is not working and i go to not existed url like http://localhost/test
and go back to previous url then, the js, surprisingly, works fine.
I think it happens because the flowbite inits before the page comletely load, at the moment when the router do its magic, but i dont know how to fix it. Anyone know how to fix that? I will be grateful for any advice.
The actual code with the problem:
import { initFlowbite } from 'flowbite'
async function isAuthenticated() {
const response = await axios.get('/api/user')
return response.data;
}
router.beforeEach(async(to, from) => {
const user = await isAuthenticated();
const isAuth = user !== ''
if (to.meta.isAuthPage === true && isAuth === true) {
return {name: 'dashboard'}
}
if (isAuth === false && to.meta.requiresAuth === true) {
return {name: 'login'}
}
})
Works fine when removing async/await, but lose required functionaluty:
import { initFlowbite } from 'flowbite'
async function isAuthenticated() {
const response = await axios.get('/api/user')
return response.data;
}
router.beforeEach((to, from) => {
const user = isAuthenticated();
const isAuth = user !== ''
if (to.meta.isAuthPage === true && isAuth === true) {
return {name: 'dashboard'}
}
if (isAuth === false && to.meta.requiresAuth === true) {
return {name: 'login'}
}
})
I also tried to put flowbiteInit()
to App component like:
import { initFlowbite } from 'flowbite'
mounted() {
initFlowbite()
},
Also tried to put init to beforeEach()
after async/await row and even to the component that vue-router renders according to route
but result is still the same.