mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
27 lines
705 B
JavaScript
27 lines
705 B
JavaScript
import isEmpty from 'lodash/isEmpty'
|
|
|
|
export default async ({ store, env, route, redirect }) => {
|
|
const publicPages = env.publicPages
|
|
// only affect non public pages
|
|
if (publicPages.indexOf(route.name) >= 0) {
|
|
return true
|
|
}
|
|
|
|
// await store.dispatch('auth/refreshJWT', 'authenticated middleware')
|
|
const isAuthenticated = await store.dispatch('auth/check')
|
|
if (isAuthenticated === true) {
|
|
return true
|
|
}
|
|
|
|
// try to logout user
|
|
// await store.dispatch('auth/logout', null, { root: true })
|
|
|
|
// set the redirect path for after the login
|
|
const params = {}
|
|
if (!isEmpty(route.path) && route.path !== '/') {
|
|
params.path = route.path
|
|
}
|
|
|
|
return redirect('/login', params)
|
|
}
|