borders/components/userInfo.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-04-10 18:26:47 +00:00
import { useSession, signIn, signOut } from "next-auth/react";
import { useEffect, useState } from "react";
2022-04-10 18:26:47 +00:00
import styles from "../styles/Components.module.css";
export default function UserInfo(borderInfo) {
const { data: session } = useSession();
const [isLoading, setLoading] = useState(false);
const [borderData, setBorderData] = useState(undefined);
useEffect(async () => {
setLoading(true);
const res = await fetch('api/user/border/@me');
const data = await res.json();
setBorderData(data);
setLoading(false);
}, []);
2022-04-10 18:26:47 +00:00
return (
<div>{
isLoading ?
<p>Loading...</p>
:
<div>
<p className={styles.description}>
{session ? `Signed in as ${session.user.name} (${borderData.discordId})` : "Not signed in"}
<br />
{session ? (
<button onClick={() => signOut()}>Sign Out</button>
) : (
<button onClick={() => signIn()}>Sign In</button>
)}
</p>
{
!!borderData ?
(<div>
<img src={session.user.image} />
<img src={`/api/border/${borderData.imageId ?? '0'}`} />
</div>)
: undefined
}
</div>
}
</div>
2022-04-10 18:26:47 +00:00
);
}