feat: New users require admin approval

- Set active=false for newly registered users
- Return RegistrationResponse instead of SessionResponse after registration
- Show success message informing user that admin approval is pending
- Login check already filters for active users only
This commit is contained in:
2026-03-17 09:28:14 +01:00
parent 3367129d37
commit 7c59944646
4 changed files with 27 additions and 10 deletions

View File

@@ -4,6 +4,11 @@ import { apiPost } from "../lib/api";
import { useSession } from "../lib/session";
import type { SessionResponse } from "../lib/types";
interface RegistrationResponse {
userId: string;
email: string;
}
type FeedbackState =
| { type: "error"; text: string }
| { type: "success"; text: string }
@@ -86,14 +91,24 @@ export default function LoginPage() {
setFeedback(null);
const { passwordConfirmation, ...registrationPayload } = registration;
void passwordConfirmation;
const response = await apiPost<SessionResponse>("/session/register", registrationPayload);
const response = await apiPost<RegistrationResponse>("/session/register", registrationPayload);
setFeedback({
type: "success",
text: `Registrierung erfolgreich. Willkommen ${response.user.companyName ?? response.user.displayName}.`,
text: `Registrierung erfolgreich. Ihr Account (${response.email}) wurde angelegt und muss durch einen Administrator freigegeben werden. Sie werden benachrichtigt, sobald die Freigabe erfolgt ist.`,
});
setSession(response);
// Admin zum Dashboard, Kunden zur Startseite
navigate(response.user.role === "ADMIN" ? "/admin/dashboard" : "/home");
// Reset registration form and switch back to login
setRegistration({
companyName: "",
street: "",
houseNumber: "",
postalCode: "",
city: "",
email: "",
phoneNumber: "",
password: "",
passwordConfirmation: "",
});
setShowRegistration(false);
} catch (registrationError) {
setFeedback({ type: "error", text: (registrationError as Error).message });
}