modifica a dati
This commit is contained in:
parent
306ac68306
commit
3cefb1b407
5 changed files with 29 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||
@echo-off
|
||||
@echo off
|
||||
cd /d D:\prenotazioni\esameits24-26\esameits24-26backend
|
||||
git status
|
||||
echo.
|
||||
|
|
|
|||
|
|
@ -13,6 +13,6 @@ USE `esameits24-26`;
|
|||
-- Utenti
|
||||
-- ------------------------------------------------------------
|
||||
INSERT INTO utente (Nome, Cognome, Email, PasswordHash, Ruolo) VALUES
|
||||
('Andrea', 'Villari', 'admin@corrieri.it', '$2b$10$7Z80qZcDydZCdLrOcaH/VOa9knKWjQVyyg8MtEgBAvgfNMsiLEZze', 'Amministratore'),
|
||||
('Maria', 'Bianchi', 'maria.bianchi@corrieri.it', '$2b$10$7Z80qZcDydZCdLrOcaH/VOa9knKWjQVyyg8MtEgBAvgfNMsiLEZze', 'Operatore'),
|
||||
('Luca', 'Conti', 'luca.conti@corrieri.it', '$2b$10$7Z80qZcDydZCdLrOcaH/VOa9knKWjQVyyg8MtEgBAvgfNMsiLEZze', 'Operatore');ZcDydZCdLrOcaH/VOa9knKWjQVyyg8MtEgBAvgfNMsiLEZze', 'DIPENDENTE');
|
||||
('Andrea', 'Villari', 'admin@example.it', '$2b$10$7Z80qZcDydZCdLrOcaH/VOa9knKWjQVyyg8MtEgBAvgfNMsiLEZze', 'Amministratore'),
|
||||
('Maria', 'Bianchi', 'maria.bianchi@example.it', '$2b$10$7Z80qZcDydZCdLrOcaH/VOa9knKWjQVyyg8MtEgBAvgfNMsiLEZze', 'Operatore'),
|
||||
('Luca', 'Conti', 'luca.conti@example.it', '$2b$10$7Z80qZcDydZCdLrOcaH/VOa9knKWjQVyyg8MtEgBAvgfNMsiLEZze', 'Operatore');ZcDydZCdLrOcaH/VOa9knKWjQVyyg8MtEgBAvgfNMsiLEZze', 'DIPENDENTE');
|
||||
11
src/index.ts
11
src/index.ts
|
|
@ -1,7 +1,10 @@
|
|||
import { ExpressAuth } from "@auth/express";
|
||||
import dotenv from "dotenv";
|
||||
import express from "express";
|
||||
|
||||
import { authConfig } from "./auth/config.js";
|
||||
import { corsMiddleware } from "./config/cors.js";
|
||||
import meRouter from "./routes/me.js";
|
||||
import utentiRouter from "./routes/utenti.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
|
|
@ -9,11 +12,17 @@ const app = express();
|
|||
const port = Number(process.env.PORT ?? 3001);
|
||||
|
||||
app.set("trust proxy", 1);
|
||||
app.use(corsMiddleware);
|
||||
app.use(express.json());
|
||||
app.options(/.*/, corsMiddleware);
|
||||
|
||||
app.get("/api/health", (_req, res) => {
|
||||
res.json({ status: "ok" });
|
||||
});
|
||||
|
||||
app.use("/api/auth", ExpressAuth(authConfig));
|
||||
app.use("/api/me", meRouter);
|
||||
app.use("/api/utenti", utentiRouter);
|
||||
|
||||
app.listen(port, "0.0.0.0", () => {
|
||||
console.log(`Server in ascolto sulla porta ${port}`);
|
||||
|
|
|
|||
15
src/routes/me.ts
Normal file
15
src/routes/me.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { Router } from "express";
|
||||
import { requireAuth } from "../middleware/auth.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/", requireAuth, (req, res) => {
|
||||
res.json({
|
||||
id: req.user!.id,
|
||||
email: req.user!.email,
|
||||
name: req.user!.name,
|
||||
ruolo: req.user!.ruolo,
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
Loading…
Add table
Reference in a new issue