"use client"; import { redirect } from "next/navigation"; import Link from "next/link"; import { signOut, useSession } from "next-auth/react"; import { useEffect, useState } from "react"; import axios from "axios"; export default function Home() { const { data: session, status } = useSession(); const [previousUsername, setPreviousUsername] = useState() // 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() { await axios.post("/api/account") } saveAccount().catch(console.error) }, []) return (
{session && ( signOut()} className="btn-signin"> Sign out )} {!session && ( Sign in )}
); }