2FAuth/resources/js_vue3/router/middlewares/starter.js

17 lines
500 B
JavaScript
Raw Normal View History

/**
* Allows an authenticated user to access the main view only if he owns at least one twofaccount.
* Push to the starter view otherwise.
*/
export default function starter({ to, next, nextMiddleware, stores }) {
const { twofaccounts } = stores
if (twofaccounts.isEmpty) {
twofaccounts.fetch().then(() => {
if (twofaccounts.isEmpty) {
next({ name: 'start' })
}
else nextMiddleware()
})
}
else nextMiddleware()
}