1
0
mirror of https://gitlab.com/bramw/baserow.git synced 2024-11-21 23:37:55 +00:00
bramw_baserow/web-frontend/modules/core/middleware/authenticated.js
2023-06-06 11:01:11 +02:00

20 lines
509 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, route, redirect }) {
// If nuxt generate, pass this middleware
if (process.server && !req) return
if (!store.getters['auth/isAuthenticated']) {
const query = {}
if (req) {
query.original = encodeURI(req.originalUrl)
} else {
query.original = route.path
}
return redirect({ name: 'login', query })
}
}