Initial commit
This commit is contained in:
commit
38c24fc9dc
166 files changed
+22002
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { apiFetch, apiPost } from '../lib/api'
|
||||
import type { SessionResponse } from '../types'
|
||||
|
||||
export function useSession() {
|
||||
return useQuery({
|
||||
queryKey: ['session'],
|
||||
queryFn: () => apiFetch<SessionResponse>('/api/v1/session'),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function useLogout() {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: () => apiPost('/api/v1/auth/logout'),
|
||||
// Full reload rather than just invalidating the session query — clears
|
||||
// any in-memory query cache holding data from the now-logged-out user,
|
||||
// and re-runs App.tsx's session check from a clean slate.
|
||||
onSuccess: () => {
|
||||
queryClient.clear()
|
||||
window.location.assign('/')
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user