1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-05-18 06:41:02 +00:00
bramw_baserow/web-frontend/modules/core/middleware/authenticated.js

18 lines
533 B
JavaScript

/**
* If this middleware is added to a page, it will redirect back to the login
* page if the user is not authenticated.
*/
export default function ({ req, store, redirect }) {
// If nuxt generate, pass this middleware
if (process.server && !req) return
// If the user is not authenticated we will redirect him to the login page.
if (!store.getters['auth/isAuthenticated']) {
const query = {}
if (req) {
query.original = encodeURI(req.originalUrl)
}
return redirect({ name: 'login', query })
}
}