Redirect on token expiry

This commit is contained in:
april
2024-01-04 13:36:21 -06:00
parent 9de454d491
commit 4e84dc842a
10 changed files with 116 additions and 34 deletions

View File

@@ -1,7 +1,10 @@
import { client } from "@/util/api";
import { useAuth } from "@/util/auth";
import { Center, Container, List, Loader, Stack, Text } from "@mantine/core";
import { useParams } from "@remix-run/react";
import { useNavigate, useParams } from "@remix-run/react";
import { IconAlertTriangle } from "@tabler/icons-react";
import { useQuery } from "@tanstack/react-query";
import { useEffect } from "react";
export default function Flight() {
const params = useParams();
@@ -10,8 +13,21 @@ export default function Flight() {
queryKey: [params.id],
queryFn: async () =>
await client.get(`/flights/${params.id}`).then((res) => res.data),
retry: (failureCount, error) => {
return !error || error.response?.status !== 401;
},
});
const navigate = useNavigate();
const { clearUser } = useAuth();
useEffect(() => {
if (flight.isError && flight.error.response.status === 401) {
clearUser();
navigate("/login");
}
}, [flight]);
return (
<Container>
<Stack h="calc(100vh - 95px)">