Merge pull request #4301 from omnivore-app/fix/web-logout-router

Use router when clearing cache on logout
This commit is contained in:
Jackson Harper
2024-08-21 18:43:43 +08:00
committed by GitHub

View File

@ -2,8 +2,10 @@ import { useQueryClient } from '@tanstack/react-query'
import { deinitAnalytics } from './analytics'
import { logoutMutation } from './networking/mutations/logoutMutation'
import { useCallback } from 'react'
import { useRouter } from 'next/router'
export const useLogout = () => {
const router = useRouter()
const queryClient = useQueryClient()
const logout = useCallback(async () => {
await logoutMutation()
@ -14,10 +16,11 @@ export const useLogout = () => {
}
deinitAnalytics()
queryClient.clear()
window.location.href = '/login'
} catch {
// TODO: display an error message instead
window.location.href = '/'
console.log('cleared the query client')
router.push('/login')
} catch (err) {
console.log('error on logout: ', err)
router.push('/')
}
}, [])
return { logout }