add error handling to ui states

This commit is contained in:
2022-12-29 03:10:32 +01:00
parent b89174d0cb
commit 7a03f14e7c
2 changed files with 29 additions and 31 deletions

View File

@@ -8,7 +8,7 @@ import Link from "next/link";
import { useUser } from "@auth0/nextjs-auth0/client";
const Navigation = () => {
const { user, isLoading } = useUser();
const { user, error, isLoading } = useUser();
return (
<>
<div className={styles.nav}>
@@ -51,25 +51,27 @@ const Navigation = () => {
</Link>
</>
)}
{!isLoading && !error && 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>
)}
{error && (
<Link href="/ja" className={`${styles.link} ${styles.profile}`}>
wystąpił błąd!
</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>
<Link
href="/api/auth/logout"
className={`${styles.link} ${styles.partprofile}`}
>
<Icon icon="LogOut" />
</Link>
</>
<Link
href="/api/auth/logout"
className={`${styles.link} ${styles.partprofile}`}
>
<Icon icon="LogOut" />
</Link>
)}
{!isLoading && !user && (
<Link

View File

@@ -2,7 +2,7 @@ import styles from "../styles/Ja.module.scss";
import { useUser } from "@auth0/nextjs-auth0/client";
const PageMe = () => {
const { user, isLoading } = useUser();
const { user, error, isLoading } = useUser();
return (
<>
{isLoading && (
@@ -11,22 +11,18 @@ const PageMe = () => {
<p>Sit tight.</p>
</main>
)}
{!isLoading && user && (
{error && (
<main>
<h3>Wystąpił błąd.</h3>
<p>Tyle wiemy.</p>
</main>
)}
{!isLoading && !error && user && (
<main>
<div className={styles.header}>
<img src={user.picture || ""} alt={`${user.name}'s picture`} />
<h1>{user.name}</h1>
</div>
{/* <p>
mail: {user.email || "no mail"} <br />
mail verified: {user.email_verified || "no mail verified"} <br />
name: {user.name || "no name"} <br />
nickname: {user.nickname || "no nickname"} <br />
org id: {user.org_id || "no org id"} <br />
picture: {user.picture || "no picture"} <br />
sub: {user.sub || "no sub"} <br />
updated at: {user.updated_at || "no updated at"}
</p> */}
</main>
)}
{!isLoading && !user && (