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