Merge pull request #23 from gractwo/authwork

add error handling to ui states
This commit is contained in:
Stanisław Dzioba
2022-12-29 03:14:24 +01:00
committed by GitHub
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"; import { useUser } from "@auth0/nextjs-auth0/client";
const Navigation = () => { const Navigation = () => {
const { user, isLoading } = useUser(); const { user, error, isLoading } = useUser();
return ( return (
<> <>
<div className={styles.nav}> <div className={styles.nav}>
@@ -51,25 +51,27 @@ const Navigation = () => {
</Link> </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 && ( {!isLoading && user && (
<> <Link
<Link href="/ja" className={`${styles.link} ${styles.profile}`}> href="/api/auth/logout"
{user.picture && ( className={`${styles.link} ${styles.partprofile}`}
<img >
src={user.picture} <Icon icon="LogOut" />
alt={`${user.name}'s profile picture`} </Link>
/>
)}
{!user.picture && <Icon icon="User" />}
{user.nickname}
</Link>
<Link
href="/api/auth/logout"
className={`${styles.link} ${styles.partprofile}`}
>
<Icon icon="LogOut" />
</Link>
</>
)} )}
{!isLoading && !user && ( {!isLoading && !user && (
<Link <Link

View File

@@ -2,7 +2,7 @@ import styles from "../styles/Ja.module.scss";
import { useUser } from "@auth0/nextjs-auth0/client"; import { useUser } from "@auth0/nextjs-auth0/client";
const PageMe = () => { const PageMe = () => {
const { user, isLoading } = useUser(); const { user, error, isLoading } = useUser();
return ( return (
<> <>
{isLoading && ( {isLoading && (
@@ -11,22 +11,18 @@ const PageMe = () => {
<p>Sit tight.</p> <p>Sit tight.</p>
</main> </main>
)} )}
{!isLoading && user && ( {error && (
<main>
<h3>Wystąpił błąd.</h3>
<p>Tyle wiemy.</p>
</main>
)}
{!isLoading && !error && user && (
<main> <main>
<div className={styles.header}> <div className={styles.header}>
<img src={user.picture || ""} alt={`${user.name}'s picture`} /> <img src={user.picture || ""} alt={`${user.name}'s picture`} />
<h1>{user.name}</h1> <h1>{user.name}</h1>
</div> </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> </main>
)} )}
{!isLoading && !user && ( {!isLoading && !user && (