diff --git a/.env b/.env new file mode 100644 index 0000000..7883457 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +POSTGRES_DB=db +POSTGRES_USER=db +POSTGRES_PASSWORD=db diff --git a/back-end/Dockerfile b/back-end/Dockerfile new file mode 100644 index 0000000..e10d115 --- /dev/null +++ b/back-end/Dockerfile @@ -0,0 +1,10 @@ +FROM docker.io/oven/bun:1.1-slim +WORKDIR /app/ +COPY package.json bun.lockb . +RUN bun install +COPY api/ api/ +COPY index.js . +COPY prisma/ prisma/ +COPY .env . +EXPOSE 3000 +CMD ["bun", "index.js"] \ No newline at end of file diff --git a/back-end/bun.lockb b/back-end/bun.lockb index 3be6064..564567e 100755 Binary files a/back-end/bun.lockb and b/back-end/bun.lockb differ diff --git a/back-end/package.json b/back-end/package.json index 4b0931a..d940fcb 100644 --- a/back-end/package.json +++ b/back-end/package.json @@ -3,18 +3,18 @@ "module": "index.ts", "type": "module", "devDependencies": { - "@types/bun": "latest", - "prisma": "5.19.1" + "@types/bun": "latest" }, "peerDependencies": { "typescript": "^5.0.0" }, "dependencies": { - "@prisma/client": "5.19.1", + "@prisma/client": "^5.20.0", "@types/express": "^4.17.21", - "@types/jsonwebtoken": "^9.0.6", + "cors": "^2.8.5", "express": "^4.21.0", "jest": "^29.7.0", + "jsonwebtoken": "^9.0.2", "supertest": "^7.0.0" }, "scripts": { diff --git a/back-end/prisma/migrations/20240908141853_init/migration.sql b/back-end/prisma/migrations/20240908141853_init/migration.sql deleted file mode 100644 index 0fc7a5f..0000000 --- a/back-end/prisma/migrations/20240908141853_init/migration.sql +++ /dev/null @@ -1,10 +0,0 @@ --- CreateTable -CREATE TABLE `User` ( - `id` INTEGER NOT NULL, - `username` VARCHAR(191) NOT NULL, - `pswd` VARCHAR(191) NOT NULL, - `email` VARCHAR(191) NOT NULL, - - UNIQUE INDEX `User_id_key`(`id`), - UNIQUE INDEX `User_email_key`(`email`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; diff --git a/back-end/prisma/migrations/20240908142435_/migration.sql b/back-end/prisma/migrations/20240908142435_/migration.sql deleted file mode 100644 index 7a5139e..0000000 --- a/back-end/prisma/migrations/20240908142435_/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE `User` MODIFY `id` INTEGER NOT NULL AUTO_INCREMENT; diff --git a/back-end/prisma/migrations/20241010152336_init/migration.sql b/back-end/prisma/migrations/20241010152336_init/migration.sql new file mode 100644 index 0000000..fabebc4 --- /dev/null +++ b/back-end/prisma/migrations/20241010152336_init/migration.sql @@ -0,0 +1,13 @@ +-- CreateTable +CREATE TABLE "User" ( + "id" SERIAL NOT NULL, + "username" TEXT NOT NULL, + "pswd" TEXT NOT NULL, + "email" TEXT NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_id_key" ON "User"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); diff --git a/back-end/prisma/migrations/migration_lock.toml b/back-end/prisma/migrations/migration_lock.toml index e5a788a..fbffa92 100644 --- a/back-end/prisma/migrations/migration_lock.toml +++ b/back-end/prisma/migrations/migration_lock.toml @@ -1,3 +1,3 @@ # Please do not edit this file manually # It should be added in your version-control system (i.e. Git) -provider = "mysql" \ No newline at end of file +provider = "postgresql" \ No newline at end of file diff --git a/back-end/prisma/schema.prisma b/back-end/prisma/schema.prisma index c8348ba..ff5e129 100644 --- a/back-end/prisma/schema.prisma +++ b/back-end/prisma/schema.prisma @@ -9,7 +9,7 @@ generator client { } datasource db { - provider = "mysql" + provider = "postgres" url = env("DATABASE_URL") } diff --git a/compose.yaml b/compose.yaml index 1d8ce4b..cf99b86 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,9 +1,46 @@ --- services: - app: - build: . + front-end: + build: ./front_end + restart: unless-stopped ports: - "8000:5173" + environment: + - PROD_URL=${PROD_URL} + depends_on: + - back-end + + back-end: + build: ./back-end + restart: unless-stopped + ports: + - "3000:3000" + command: + - sh + - -c + - "bunx prisma migrate deploy && bunx prisma generate && bun index.js" + environment: + - POSTGRES_DB + - POSTGRES_USER + - POSTGRES_PASSWORD + - POSTGRES_HOST=db + depends_on: + - redis + - db redis: image: "valkey/valkey:7" + restart: unless-stopped + + db: + image: "postgres:17" + restart: unless-stopped + environment: + - POSTGRES_DB + - POSTGRES_USER + - POSTGRES_PASSWORD + volumes: + - db:/var/lib/postgresql/data + +volumes: + db: diff --git a/Dockerfile b/front_end/Dockerfile similarity index 100% rename from Dockerfile rename to front_end/Dockerfile diff --git a/front_end/src/files/Profil.jsx b/front_end/src/files/Profil.jsx new file mode 100644 index 0000000..2c244a3 --- /dev/null +++ b/front_end/src/files/Profil.jsx @@ -0,0 +1,3 @@ +export function Profil() { + return

profil page

; +} diff --git a/front_end/src/files/Sign_in.jsx b/front_end/src/files/Sign_in.jsx index d736e15..d22121e 100644 --- a/front_end/src/files/Sign_in.jsx +++ b/front_end/src/files/Sign_in.jsx @@ -25,6 +25,7 @@ export function SignIn() { const data = await response.json(); alert("Login successful:", data); + //login(); } catch (error) { console.error("Error during login:", error); alert("Error during login: " + error.message); diff --git a/front_end/src/services/AuthContext.jsx b/front_end/src/services/AuthContext.jsx new file mode 100644 index 0000000..a22bc0f --- /dev/null +++ b/front_end/src/services/AuthContext.jsx @@ -0,0 +1,25 @@ +import { createContext, useContext, useState } from "react"; + +const AuthContext = createContext(); + +export function AuthProvider({ children }) { + const [isAuthenticated, setIsAuthenticated] = useState(false); + + const login = () => { + setIsAuthenticated(true); + }; + + const logout = () => { + setIsAuthenticated(false); + }; + + return ( + + {children} + + ); +} + +export function useAuth() { + return useContext(AuthContext); +} diff --git a/front_end/src/services/Router.jsx b/front_end/src/services/Router.jsx index e4d9bdf..1328af8 100644 --- a/front_end/src/services/Router.jsx +++ b/front_end/src/services/Router.jsx @@ -21,6 +21,12 @@ export const router = createBrowserRouter([ { path: "/sign-in", element: , + children: [ + { + path: "profil", + /* element: } />, */ + }, + ], }, { path: "/register",