This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/saveLastVisited.ts
kolaente f7e22c8c56
All checks were successful
continuous-integration/drone/push Build is passing
fix(auth): correctly redirect the user to the last visited page after login
Resolves #3682
2023-08-24 12:15:45 +02:00

23 lines
538 B
TypeScript

const LAST_VISITED_KEY = 'lastVisited'
export const saveLastVisited = (name: string | undefined, params: object, query: object) => {
if (typeof name === 'undefined') {
return
}
localStorage.setItem(LAST_VISITED_KEY, JSON.stringify({name, params, query}))
}
export const getLastVisited = () => {
const lastVisited = localStorage.getItem(LAST_VISITED_KEY)
if (lastVisited === null) {
return null
}
return JSON.parse(lastVisited)
}
export const clearLastVisited = () => {
return localStorage.removeItem(LAST_VISITED_KEY)
}