2023-12-30 05:56:40 -05:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { redirect } from "next/navigation";
|
|
|
|
import Link from "next/link";
|
2024-01-04 02:14:11 -05:00
|
|
|
import { signOut, useSession } from "next-auth/react";
|
2023-12-30 05:56:40 -05:00
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import axios from "axios";
|
|
|
|
|
|
|
|
|
|
|
|
export default function Home() {
|
|
|
|
const { data: session, status } = useSession();
|
|
|
|
const [previousUsername, setPreviousUsername] = useState<string>()
|
|
|
|
|
|
|
|
// if (status !== "authenticated") {
|
|
|
|
// redirect('/api/auth/signin?redirectUrl=/');
|
|
|
|
// }
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (status !== "authenticated" || previousUsername == session.user?.name) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
setPreviousUsername(session.user?.name as string)
|
|
|
|
|
|
|
|
async function saveAccount() {
|
2024-08-25 17:35:46 -04:00
|
|
|
await axios.post("/api/account")
|
2023-12-30 05:56:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
saveAccount().catch(console.error)
|
2024-08-14 16:33:40 -04:00
|
|
|
}, [])
|
2023-12-30 05:56:40 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<main
|
|
|
|
style={{
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "center",
|
|
|
|
alignItems: "center",
|
|
|
|
height: "70vh",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="header">
|
|
|
|
{session && (
|
|
|
|
<Link href="#" onClick={() => signOut()} className="btn-signin">
|
|
|
|
Sign out
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
{!session && (
|
2024-01-04 02:14:11 -05:00
|
|
|
<Link href="/auth/login" className="btn-signin">
|
2023-12-30 05:56:40 -05:00
|
|
|
Sign in
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|