Added tester React frontend, changed DTOs and User and UserRepository to fit around specialize USER key

This commit is contained in:
2025-01-04 13:37:11 -05:00
parent fdbbcc8386
commit 3eba8eed73
33 changed files with 6839 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -0,0 +1,21 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
:root {
--background: #ffffff;
--foreground: #171717;
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
}

View File

@@ -0,0 +1,34 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}

View File

@@ -0,0 +1,117 @@
"use client"
import Image from "next/image";
import { useState } from "react";
export default function Home() {
const [email, setEmail] = useState<string>('');
const [password, setPassword] = useState<string>('');
const [error, setError] = useState<string | null>(null);
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setError(null);
try {
const response = await fetch('http://localhost:8080/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email, password }),
});
if (!response.ok) {
throw new Error('Failed to login');
}
const data = await response.json();
console.log('Login successful', data);
} catch (error) {
console.error(error);
}
}
const handleRegister = async (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
setError(null);
const firstName = "first_name";
const lastName = "last_name";
const username = "username";
try {
const response = await fetch('http://localhost:8080/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, firstName, lastName, email, password }),
});
if (!response.ok) {
throw new Error('Failed to register');
}
const data = await response.json();
console.log('Register successful', data);
} catch (error) {
console.error(error);
}
}
return (
<div style={{ maxWidth: '400px', margin: '50px auto', padding: '20px', border: '1px solid #ccc', borderRadius: '8px', backgroundColor: 'black', color: 'black' }}>
<h1 style={{ textAlign: 'center', color: 'white' }}>Login</h1>
<form onSubmit={handleSubmit}>
<div style={{ marginBottom: '15px' }}>
<label htmlFor="email" style={{ display: 'block', marginBottom: '5px', color: 'white' }}>Email:</label>
<input
type="email"
id="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
style={{ width: '100%', padding: '8px', boxSizing: 'border-box' }}
/>
</div>
<div style={{ marginBottom: '15px' }}>
<label htmlFor="password" style={{ display: 'block', marginBottom: '5px', color: 'white' }}>Password:</label>
<input
type="password"
id="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
style={{ width: '100%', padding: '8px', boxSizing: 'border-box' }}
/>
</div>
<button
type="submit"
style={{
width: '100%',
padding: '10px',
backgroundColor: '#0070f3',
color: 'white',
border: 'none',
borderRadius: '4px',
}}
>
Login
</button>
<button
type="button"
onClick={handleRegister}
style={{
margin: '10px 0',
width: '100%',
padding: '10px',
backgroundColor: '#0070f3',
color: 'white',
border: 'none',
borderRadius: '4px',
}}
>
Register
</button>
</form>
</div>
);
};