feat(auth): enterprise authentication and user management
This commit is contained in:
parent
4bc8b20a21
commit
86a32a942c
36 changed files with 2239 additions and 324 deletions
|
|
@ -1,24 +1,20 @@
|
|||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function LoginPage() {
|
||||
const router = useRouter();
|
||||
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function handleLogin(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
|
||||
setError("");
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/auth/login`,
|
||||
{
|
||||
try {
|
||||
const response = await fetch("/api/login", {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
|
|
@ -26,15 +22,20 @@ export default function LoginPage() {
|
|||
username,
|
||||
password,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
window.location.href = "/dashboard";
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
router.push("/dashboard");
|
||||
return;
|
||||
setError(data.detail ?? "Login fehlgeschlagen");
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
setError("Technischer Fehler");
|
||||
}
|
||||
|
||||
setError("Benutzername oder Passwort ist falsch.");
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -63,12 +64,11 @@ export default function LoginPage() {
|
|||
/>
|
||||
|
||||
{error && (
|
||||
<p className="mb-4 text-red-600">
|
||||
{error}
|
||||
</p>
|
||||
<p className="mb-4 text-red-600">{error}</p>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="w-full rounded bg-blue-600 p-3 text-white hover:bg-blue-700"
|
||||
>
|
||||
Anmelden
|
||||
|
|
@ -76,4 +76,4 @@ export default function LoginPage() {
|
|||
</form>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue