add reflection of user's login state to navbar

This commit is contained in:
2022-12-28 17:05:55 +01:00
parent 6b4a025e0e
commit d1feca9544
2 changed files with 56 additions and 17 deletions

View File

@@ -20,10 +20,24 @@
color: var(--color); color: var(--color);
} }
} }
.partprofile {
background: rgba(255, 255, 255, 0.1);
display: flex;
flex-direction: row;
align-items: center;
gap: 8px;
}
.profile { .profile {
background: rgba(255, 255, 255, 0.1);
display: flex;
flex-direction: row;
align-items: center;
gap: 8px;
margin-left: auto; margin-left: auto;
background: var(--color); img {
color: var(--backdrop); height: 2.3rem;
border-radius: 50%;
}
} }
.logo { .logo {
padding: 0 1rem; padding: 0 1rem;

View File

@@ -5,8 +5,10 @@ import { Icon } from "../Icon";
import navigation from "../../data/navigation.json"; import navigation from "../../data/navigation.json";
import Link from "next/link"; import Link from "next/link";
import { useUser } from "@auth0/nextjs-auth0/client";
const Navigation = () => { const Navigation = () => {
let username: string = ""; const { user, isLoading } = useUser();
return ( return (
<> <>
<div className={styles.nav}> <div className={styles.nav}>
@@ -42,20 +44,43 @@ const Navigation = () => {
})} })}
</div> </div>
</div> </div>
{isLoading && (
<>
<Link href="/" className={`${styles.link} ${styles.profile}`}>
fetching danych...
</Link>
</>
)}
{!isLoading && user && (
<>
<Link href="/ja" className={`${styles.link} ${styles.profile}`}>
{user.picture && (
<img
src={user.picture}
alt={`${user.name}'s profile picture`}
/>
)}
{!user.picture && <Icon icon="User" />}
{user.nickname}
</Link>
<a
href="/api/auth/logout"
className={`${styles.link} ${styles.partprofile}`}
>
<Icon icon="LogOut" />
</a>
</>
)}
{!isLoading && !user && (
<a <a
href="/api/auth/login" href="/api/auth/login"
style={{ display: "flex" }} style={{ display: "flex" }}
className={`${styles.link} ${styles.profile}`} className={`${styles.link} ${styles.partprofile}`}
> >
zaloguj się zaloguj się
<Icon icon="LogIn" />
</a> </a>
<Link )}
href=""
style={{ display: "none" }}
className={`${styles.link} ${styles.profile}`}
>
{username ? username : "twój profil"}
</Link>
</div> </div>
</> </>
); );