add register page. add db service
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
<div>None</div>
|
||||
</div>
|
||||
</div>
|
||||
<a href="/login">Login</a><br />
|
||||
<a href="/register">Register</a><br />
|
||||
</div>
|
||||
|
||||
<div id="map"></div>
|
||||
|
||||
@@ -3,11 +3,17 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>LOGIN</h1>
|
||||
<a href="/">Game</a>
|
||||
<div id="login">
|
||||
<input type="text" name="user" id="user" /><br />
|
||||
<label for="email">Email</label>
|
||||
<input type="email" name="email" id="email" /><br />
|
||||
<label for="password">Password</label>
|
||||
<input type="password" name="password" id="password" /><br />
|
||||
<button id="login-button">Login</button>
|
||||
</div>
|
||||
<div>
|
||||
<a href="/register">Register?</a>
|
||||
</div>
|
||||
|
||||
<script type="module" src="/src/login.ts"></script>
|
||||
</body>
|
||||
|
||||
@@ -8,7 +8,8 @@ datasource db {
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
email String @unique
|
||||
name String?
|
||||
id Int @id @default(autoincrement())
|
||||
email String @unique
|
||||
name String?
|
||||
password String
|
||||
}
|
||||
|
||||
20
register.html
Normal file
20
register.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!doctype html>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<h1>REGISTER</h1>
|
||||
<a href="/">Game</a>
|
||||
<div id="login">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" name="user" id="email" /><br />
|
||||
<label for="password">Password</label>
|
||||
<input type="password" name="password" id="password" /><br />
|
||||
<button id="login-button">Register</button>
|
||||
</div>
|
||||
<div>
|
||||
<a href="/login">Login?</a>
|
||||
</div>
|
||||
|
||||
<script type="module" src="/src/login.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
12
server.ts
12
server.ts
@@ -1,11 +1,23 @@
|
||||
import { Hono } from "hono";
|
||||
import { upgradeWebSocket, websocket } from "hono/bun";
|
||||
import { DatabaseService } from "@/services/database-service";
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
app.get("/", async (c) => {
|
||||
const database = new DatabaseService();
|
||||
await database.getClient().user.create({
|
||||
data: {
|
||||
email: "rosati5.matteo@gmail.com",
|
||||
name: "Matteo",
|
||||
},
|
||||
});
|
||||
|
||||
const users = await database.getClient().user.findMany();
|
||||
|
||||
return c.json({
|
||||
message: "ok",
|
||||
users: users,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -35,6 +35,14 @@ body {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
#info > a:link,
|
||||
#info > a:visited,
|
||||
#info > a:hover,
|
||||
#info > a:active {
|
||||
color: #ffffff;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.info-box {
|
||||
margin: 10px;
|
||||
padding: 10px;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { User } from "@/orm/generated/prisma/browser";
|
||||
|
||||
export class AuthService {
|
||||
public login = (user: string, password: string): string => {
|
||||
return "token";
|
||||
@@ -6,4 +8,8 @@ export class AuthService {
|
||||
public logout = (): boolean => {
|
||||
return true;
|
||||
};
|
||||
|
||||
public getUser(): User | null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
17
src/services/database-service.ts
Normal file
17
src/services/database-service.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { PrismaPg } from "@prisma/adapter-pg";
|
||||
import { PrismaClient } from "@/orm/generated/prisma";
|
||||
|
||||
export class DatabaseService {
|
||||
private prisma: PrismaClient;
|
||||
|
||||
constructor() {
|
||||
const databaseUrl = `${Bun.env.DATABASE_URL}`;
|
||||
const adapter = new PrismaPg({ connectionString: databaseUrl });
|
||||
|
||||
this.prisma = new PrismaClient({ adapter });
|
||||
}
|
||||
|
||||
public getClient(): PrismaClient {
|
||||
return this.prisma;
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,9 @@
|
||||
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
"@/*": ["./src/*", "./server.ts"],
|
||||
},
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "./server.ts"],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import { resolve } from "path";
|
||||
import FullReload from "vite-plugin-full-reload";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
FullReload(["*.html"], { delay: 200 }),
|
||||
],
|
||||
plugins: [FullReload(["*.html"], { delay: 200 })],
|
||||
server: {
|
||||
watch: {
|
||||
usePolling: true,
|
||||
@@ -24,10 +22,6 @@ export default defineConfig({
|
||||
build: {
|
||||
chunkSizeWarningLimit: 1600,
|
||||
rollupOptions: {
|
||||
input: {
|
||||
main: resolve(__dirname, "index.html"),
|
||||
login: resolve(__dirname, "login.html"),
|
||||
},
|
||||
output: {
|
||||
manualChunks(id) {
|
||||
if (id.includes("node_modules")) {
|
||||
|
||||
Reference in New Issue
Block a user