honkstyle
04/07/2022, 4:55 PM<RequireAuth>
(navigates to /login
if not logged in) component for my routes. My goal is that when a user logs out, they get sent to "/"
. What actually happens is user is first navigated to /login
and then to /
.honkstyle
04/07/2022, 4:57 PMexport const RequireAuth = ({ children }: { children: JSX.Element}) => {
let auth = useContext(AuthContext)
let location = useLocation()
if (!auth.user) {
return <Navigate to={"/login"} state={{ from: location }} replace />
}
return children
}
honkstyle
04/07/2022, 4:58 PMlet signout = async (callback: VoidFunction) => {
let {error} = await client.auth.signOut()
if (error) console.log("Error: ", error.message)
callback()
}
the callback is literally () => {navigate("/")}