add login / logout logic for user
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
import { useCurrentUser } from "@/services/api";
|
||||
import { Group, Loader } from "@mantine/core";
|
||||
import { Navigate, Outlet } from "react-router";
|
||||
|
||||
export function Auth() {
|
||||
const { data: userLogged, isLoading } = useCurrentUser();
|
||||
|
||||
if (!userLogged && isLoading)
|
||||
return (
|
||||
<Group align="center" justify="center" h="80vh" w="100%">
|
||||
<Loader color="pink" />
|
||||
</Group>
|
||||
);
|
||||
|
||||
if (!userLogged?.logged) {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
|
||||
return <Outlet />;
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
import { NavLink } from "react-router";
|
||||
import { t } from "@/config/i18n";
|
||||
import "./index.css";
|
||||
import { Button, Group, Loader } from "@mantine/core";
|
||||
import { Group, Loader } from "@mantine/core";
|
||||
import { Config } from "@/config/config";
|
||||
import { useCurrentUser, useLogoutUser } from "@/services/api";
|
||||
import { useAuth } from "@/services/auth/AuthProvider";
|
||||
|
||||
export function Navbar() {
|
||||
const { data: user, isLoading } = useCurrentUser();
|
||||
const logout = useLogoutUser();
|
||||
const { loggedUser: user, isLoading } = useAuth();
|
||||
|
||||
if (!user && isLoading) {
|
||||
return (
|
||||
<Group align="center" justify="center" h="80vh" w="100%">
|
||||
@@ -37,15 +37,14 @@ export function Navbar() {
|
||||
{t("login with keycloak", { capfirst: true })}
|
||||
</NavLink>
|
||||
) : (
|
||||
<Button
|
||||
<a
|
||||
href={`${Config.backend_uri}/auth/logout`}
|
||||
className={"navLink"}
|
||||
aria-label={t("logout", { capfirst: true })}
|
||||
onClick={() => {
|
||||
logout.mutate();
|
||||
}}
|
||||
|
||||
>
|
||||
{t("logout", { capfirst: true })}
|
||||
</Button>
|
||||
</a>
|
||||
)}
|
||||
</nav>
|
||||
);
|
||||
|
||||
@@ -55,7 +55,7 @@ export default function ShipmentModal({
|
||||
}, [allForms]);
|
||||
|
||||
const productsSelect = useMemo(() => {
|
||||
if (!allProducts) return;
|
||||
if (!allProducts || !allProductors) return;
|
||||
return allProductors?.map((productor) => {
|
||||
return {
|
||||
group: productor.name,
|
||||
|
||||
Reference in New Issue
Block a user