Skip to content

Commit

Permalink
🚸 Invalidates Query Caches when unauthenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed Jan 25, 2023
1 parent 052a336 commit c8b2531
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/views/LoginView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SubmitHandler, useForm } from 'react-hook-form'
import { useNavigate } from 'react-router'
import useAuth from '../components/useAuth'
import logo from '../assets/logo.png'
import { useQueryClient } from '@tanstack/react-query'

interface FormValues {
email: string
Expand All @@ -23,13 +24,19 @@ const LoginView: FC = () => {
const { getValues, handleSubmit, register, reset } = useForm<FormValues>()
const { login, error, user } = useAuth()
const navigate = useNavigate()
const queryClient = useQueryClient()

const onSubmit: SubmitHandler<FormValues> = ({ email, password }) => {
login(email, password)
}

useEffect(() => {
if (user) navigate('/')
if (user) {
navigate('/')
} else {
// We want to ensure logged out users will not have any caches stored
queryClient.invalidateQueries()
}
})

useEffect(() => {
Expand Down

0 comments on commit c8b2531

Please sign in to comment.