diff --git a/flightscore/src/app-root.ts b/flightscore/src/app-root.ts
index f639d5e..b06b650 100644
--- a/flightscore/src/app-root.ts
+++ b/flightscore/src/app-root.ts
@@ -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) ─────────────────────
{
diff --git a/flightscore/src/pages/auth/register-page.ts b/flightscore/src/pages/auth/register-page.ts
index 55dd936..fd5e97b 100644
--- a/flightscore/src/pages/auth/register-page.ts
+++ b/flightscore/src/pages/auth/register-page.ts
@@ -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,
- }
- );
- window.dispatchEvent(
- new CustomEvent('nav', {
- detail: { path: '/login' },
- bubbles: true,
- composed: true,
- })
- );
- } catch (e: any) {
- this.error = e.message || 'Registration failed';
+ }),
+ });
+
+ if (!response.ok) {
+ const err = await response.json().catch(() => null);
+ this.error = err?.message ?? 'Registration failed';
+ return;
+ }
+
+ window.dispatchEvent(new CustomEvent('nav', {
+ detail: { path: '/login' },
+ bubbles: true,
+ composed: true,
+ }));
+ } 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)}
>
- (this.email = e.detail.value)}
+ @value-changed=${(e: CustomEvent) => (this.email = e.detail.value)}
>
- (this.password = e.detail.value)}
+ @value-changed=${(e: CustomEvent) => (this.password = e.detail.value)}
>
-
+
${this.loading ? 'Creating account...' : 'Create account'}