60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
"use client";
|
|
|
|
import { Suspense, useState, useEffect } from "react";
|
|
import AuthLoginForm from "./AuthLoginForm"
|
|
import SigninButton from "./SigninButton";
|
|
import { handleGoogleLogin } from "@/app/actions/GoogleAction";
|
|
import { useSearchParams } from "next/navigation";
|
|
|
|
function LoginContent() {
|
|
const [elogin, setElogin] = useState(false);
|
|
const showEmailLogin = () => { // lets you toggle on and off showEmailLogin which is used to decide if the authloginform is shown
|
|
setElogin(!elogin);
|
|
};
|
|
|
|
const searchParams = useSearchParams();
|
|
const isJustRegisted = searchParams.get("registered") === "true"; // if redirected with reigstered = true
|
|
|
|
useEffect(() => {
|
|
if (isJustRegisted) {
|
|
setElogin(true);
|
|
}
|
|
}, [isJustRegisted]);
|
|
|
|
return (
|
|
<>
|
|
<h2 className="card-title text-2xl justify-center">Please Sign In</h2>
|
|
<form className="mt-4">
|
|
{isJustRegisted && ( // display if redirect with search param
|
|
<div className="p-10 bg-emerald-1001 text-emerald-700 mb-15 rounded-md">
|
|
Account created successfully. You can now sign in.
|
|
</div>
|
|
)}
|
|
<SigninButton
|
|
text="Google"
|
|
style="btn btn-primary w-full"
|
|
formAction={handleGoogleLogin}
|
|
/>
|
|
</form>
|
|
<div className="mt-4">
|
|
<SigninButton
|
|
text="Email"
|
|
style="btn btn-primary w-full"
|
|
callback={showEmailLogin}
|
|
/>
|
|
</div>
|
|
<div className="mt-4">{elogin ? <AuthLoginForm /> : ""}</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default function LoginPage() { // displays fallback while url dependent content loads (searchparams), errors if it tries to prepare page in advance
|
|
return (
|
|
<>
|
|
<Suspense fallback={<p>Loading login..</p>}>
|
|
<LoginContent />
|
|
</Suspense>
|
|
</>
|
|
|
|
);
|
|
} |