mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import isEmpty from 'lodash/isEmpty'
|
|
import { VERSION } from '~/pages/terms-and-conditions'
|
|
|
|
export default async ({ store, env, route, redirect }) => {
|
|
let 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')
|
|
|
|
// TODO: find a better solution to **reliably** get the user
|
|
// having the encrypted JWT does not mean we have access to the user object
|
|
const user = await store.getters['auth/user']
|
|
|
|
const upToDate = user.termsAndConditionsAgreedVersion === VERSION
|
|
|
|
if (isAuthenticated === true && upToDate) {
|
|
return true
|
|
}
|
|
|
|
// try to logout user
|
|
// await store.dispatch('auth/logout', null, { root: true })
|
|
|
|
// set the redirect path for after the login
|
|
let params = {}
|
|
if (!isEmpty(route.path) && route.path !== '/' && route.path !== 'terms-and-conditions-confirm') {
|
|
params.path = route.path
|
|
}
|
|
console.log("ÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖö")
|
|
if (!upToDate) {
|
|
console.log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
|
return redirect('/terms-and-conditions-confirm', params)
|
|
} else {
|
|
return redirect('/login', params)
|
|
}
|
|
}
|