I just setup middleware by checking cookie in nuxt but it's give me blank error, nothing error in console
this is my middleware authenticate.js
export default function({ store, redirect }) {
const Cookie = process.client ? require('js-cookie') : undefined
// If the user is not authenticated
let token = Cookie.get('token')
const userIsLoggedIn = token != null //cookie ada
const userNeedLogin = token == null //cookie gak ada
if (userNeedLogin) {
return redirect('/login')
}
if (userIsLoggedIn) {
return redirect('/dashboard')
}
}
and this is my nuxt.config.js
router: {
middleware: 'authenticate'
}
it should redirect to page login when cookies is null but if cookie exist it redirect goes to dashboard, do i miss something ?