mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-02-06 22:00:09 +00:00
19 lines
509 B
JavaScript
19 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 })
|
|
}
|
|
}
|