mirror of
https://github.com/IT4Change/gradido.git
synced 2026-01-20 20:01:31 +00:00
# Conflicts: # admin/src/router/guards.js # admin/src/store/store.js # backend/src/graphql/resolver/UserResolver.ts # frontend/src/components/SidebarPlugin/SideBar.vue # frontend/src/graphql/queries.js # frontend/src/routes/guards.js
40 lines
983 B
JavaScript
40 lines
983 B
JavaScript
import { verifyLogin } from '../graphql/queries'
|
|
|
|
const addNavigationGuards = (router, store, apollo) => {
|
|
// handle publisherId
|
|
router.beforeEach((to, from, next) => {
|
|
const publisherId = to.query.pid
|
|
if (publisherId) {
|
|
store.commit('publisherId', publisherId)
|
|
delete to.query.pid
|
|
}
|
|
next()
|
|
})
|
|
|
|
// store token on authenticate
|
|
router.beforeEach(async (to, from, next) => {
|
|
if (to.path === '/authenticate' && to.query.token) {
|
|
store.commit('token', to.query.token)
|
|
const result = await apollo.query({
|
|
query: verifyLogin,
|
|
fetchPolicy: 'network-only',
|
|
})
|
|
store.dispatch('login', result.data.verifyLogin)
|
|
next({ path: '/overview' })
|
|
} else {
|
|
next()
|
|
}
|
|
})
|
|
|
|
// handle authentication
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.meta.requiresAuth && !store.state.token) {
|
|
next({ path: '/login' })
|
|
} else {
|
|
next()
|
|
}
|
|
})
|
|
}
|
|
|
|
export default addNavigationGuards
|