Skip to content

Commit

Permalink
Enhance Log Out Button Functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
C0dewithLokesh committed Oct 8, 2023
1 parent 2fd673e commit 3f00d1b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion context/Authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { graphqlClient } from '@/api'
import { signinWithEmailAndPasswordQuery } from '@/graphql/queries/user'
import { useQueryClient } from '@tanstack/react-query'
import { useCreateUser } from '@/hooks/mutation/user'
import { useRouter } from 'next/router'

interface AuthenticationProviderProps {
children?: React.ReactNode
Expand Down Expand Up @@ -37,6 +38,8 @@ export const AuthenticationProvider: React.FC<AuthenticationProviderProps> = (
) => {
const { children } = props

const router = useRouter()

const queryClient = useQueryClient()
const { mutateAsync: createUserWithEmailPassword } = useCreateUser()

Expand Down Expand Up @@ -67,7 +70,8 @@ export const AuthenticationProvider: React.FC<AuthenticationProviderProps> = (
if (!isClient) return
localStorage.removeItem('__authentication_token__')
await queryClient.invalidateQueries({ queryKey: ['current-user'] })
}, [queryClient, isClient])
router.push('/signin')
}, [queryClient, isClient, router])

return (
<AuthenticationContext.Provider
Expand Down

0 comments on commit 3f00d1b

Please sign in to comment.