frontend/src/composables/useRedirectToLastVisited.ts
kolaente f68bb2625e
feat: persist link share auth rule in url hash
This allows sharing links to a task directly. We're using hashes instead
of query parameters because hash values are usually not logged in access
logs.

With this change, when a user uses a link share, the link share hash
will be appended to all urls while browsing. When a link share hash is
encountered in the current url and the user is not authenticated, they
will be redirected to the link share auth page, get authenticated and
then get redirected to whatever url they were previously on.
2023-06-19 15:28:05 +02:00

35 lines
611 B
TypeScript

import {useRouter} from 'vue-router'
import {getLastVisited, clearLastVisited} from '@/helpers/saveLastVisited'
export function useRedirectToLastVisited() {
const router = useRouter()
function getRedirectRoute() {
const last = getLastVisited()
if (last !== null) {
clearLastVisited()
return {
name: last.name,
params: last.params,
query: last.query,
}
}
return null
}
function redirectIfSaved() {
const lastRoute = getRedirectRoute()
if (lastRoute) {
router.push(lastRoute)
}
router.push({name: 'home'})
}
return {
redirectIfSaved,
getRedirectRoute,
}
}