4466ba436b
## Description This PR ensures that the default prettier config is used for examples and templates. This config is compatible with `prettier@3` as well (upgrading prettier is bigger change that can be a future PR). ## Changes - Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will be needed upgrading to prettier@3) - Added `examples/.prettierrc.json` with default config (this will change every example) - Added `packages/create-next-app/templates/.prettierrc.json` with default config (this will change every template) ## Related - Fixes #54402 - Closes #54409
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
import { useState } from "react";
|
|
import Router from "next/router";
|
|
import { useUser } from "../lib/hooks";
|
|
import Layout from "../components/layout";
|
|
import Form from "../components/form";
|
|
|
|
const Login = () => {
|
|
useUser({ redirectTo: "/", redirectIfFound: true });
|
|
|
|
const [errorMsg, setErrorMsg] = useState("");
|
|
|
|
async function handleSubmit(e) {
|
|
e.preventDefault();
|
|
|
|
if (errorMsg) setErrorMsg("");
|
|
|
|
const body = {
|
|
username: e.currentTarget.username.value,
|
|
password: e.currentTarget.password.value,
|
|
};
|
|
|
|
try {
|
|
const res = await fetch("/api/login", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body),
|
|
});
|
|
if (res.status === 200) {
|
|
Router.push("/");
|
|
} else {
|
|
throw new Error(await res.text());
|
|
}
|
|
} catch (error) {
|
|
console.error("An unexpected error happened occurred:", error);
|
|
setErrorMsg(error.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Layout>
|
|
<div className="login">
|
|
<Form isLogin errorMessage={errorMsg} onSubmit={handleSubmit} />
|
|
</div>
|
|
<style jsx>{`
|
|
.login {
|
|
max-width: 21rem;
|
|
margin: 0 auto;
|
|
padding: 1rem;
|
|
border: 1px solid #ccc;
|
|
border-radius: 4px;
|
|
}
|
|
`}</style>
|
|
</Layout>
|
|
);
|
|
};
|
|
|
|
export default Login;
|