Added Registerpage

This commit is contained in:
Jan Meinl
2026-04-12 15:45:18 +02:00
parent b47c9ce5db
commit bed5ee4179
2 changed files with 33 additions and 26 deletions
+8
View File
@@ -57,6 +57,14 @@ export class AppRoot extends LitElement {
return document.createElement('login-page');
},
},
{
path: '/register',
auth: 'public',
view: async () => {
await import('./pages/auth/register-page.js');
return document.createElement('register-page');
},
},
// ── Target Team (Code-geschützt) ─────────────────────
{
+21 -22
View File
@@ -1,6 +1,5 @@
import { LitElement, html, css } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { apiPost } from '../../api/api';
import '../../components/auth-card.ts';
import '../../components/form-input.ts';
import '../../components/ui-button';
@@ -34,23 +33,30 @@ export class RegisterPage extends LitElement {
this.error = null;
this.loading = true;
try {
await apiPost<{ id: number; name: string; email: string }>(
'/api/auth/register',
{
//const response = await fetch('/api/auth/register', {
const response = await fetch('http://127.0.0.1:8080/auth/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: this.name,
email: this.email,
password: this.password,
}),
});
if (!response.ok) {
const err = await response.json().catch(() => null);
this.error = err?.message ?? 'Registration failed';
return;
}
);
window.dispatchEvent(
new CustomEvent('nav', {
window.dispatchEvent(new CustomEvent('nav', {
detail: { path: '/login' },
bubbles: true,
composed: true,
})
);
} catch (e: any) {
this.error = e.message || 'Registration failed';
}));
} catch {
this.error = 'Netzwerkfehler. Bitte erneut versuchen.';
} finally {
this.loading = false;
}
@@ -66,8 +72,7 @@ export class RegisterPage extends LitElement {
label="Name"
placeholder="Your full name"
.value=${this.name}
@value-changed=${(e: CustomEvent) =>
(this.name = e.detail.value)}
@value-changed=${(e: CustomEvent) => (this.name = e.detail.value)}
></form-input>
<form-input
@@ -75,8 +80,7 @@ export class RegisterPage extends LitElement {
type="email"
placeholder="you@example.com"
.value=${this.email}
@value-changed=${(e: CustomEvent) =>
(this.email = e.detail.value)}
@value-changed=${(e: CustomEvent) => (this.email = e.detail.value)}
></form-input>
<form-input
@@ -84,17 +88,12 @@ export class RegisterPage extends LitElement {
type="password"
placeholder="Choose a password"
.value=${this.password}
@value-changed=${(e: CustomEvent) =>
(this.password = e.detail.value)}
@value-changed=${(e: CustomEvent) => (this.password = e.detail.value)}
></form-input>
<notify-bar type="error" .message=${this.error}></notify-bar>
<ui-button
full
?disabled=${this.loading}
@click=${this.handleRegister}
>
<ui-button full ?disabled=${this.loading} @click=${this.handleRegister}>
${this.loading ? 'Creating account...' : 'Create account'}
</ui-button>