import { Alert, AlertTitle, Button, TextField, useTheme } from "@mui/material"; import { GetStaticProps } from "next"; import { signIn } from "next-auth/react"; import Head from "next/head"; import Image from "next/image"; import { useRouter } from "next/router"; import { useContext, useState } from "react"; import Menu from "../components/Menu"; import { Providers, getProviders } from "../types/providers"; import Link from "../components/Link"; import { TranslateContext } from "../Modules/context"; import { getData } from "./api/theme"; import { getProviderDetails } from "./signin"; import db from "#database"; interface Props { enabledProviders: Providers[]; enablePasswordSignup: boolean; } export default function SignIn({ enabledProviders, enablePasswordSignup, }: Props) { const t = useContext(TranslateContext); const router = useRouter(); const callbackUrl = router.query.callbackUrl as string; const error = router.query.error as string; const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const providers = getProviderDetails(enabledProviders); const theme = useTheme(); const dark = theme.palette.mode === "dark"; return ( <> {t("Login Page")} {error && ( {error === "CredentialsSignin" ? t("Wrong Credentials") : error === "no_username" ? t("No Username or Password") : t("Failed to Sign in")} {error === "CredentialsSignin" ? t("Check that you entered the correct username and password. ") : error === "no_username" ? t( "You need to give a username and a password when signing up. ", ) : t("Try logging in again. ")} )}
<>

{t("Sign Up Page")}

{providers.map((e, idx) => ( ))} {enablePasswordSignup && ( <>

{t( "It is recommended against using password authorization unless strictly necessary. ", )}

{ setUsername(e.target.value); }} value={username} /> { setPassword(e.target.value); }} value={password} /> )}

{t("Note that by signing up you agree to the privacy policy. ")}

); } // Gets the list of providers export const getStaticProps: GetStaticProps = async (ctx) => { const props: Props = { enabledProviders: getProviders(), enablePasswordSignup: getProviders().length === 0 || (await db .selectFrom("data") .selectAll() .where("value1", "=", "configEnablePasswordSignup") .where("value2", "=", "1") .executeTakeFirst()) !== undefined, }; return { props: { ...props, t: await getData(ctx), }, }; };