diff --git a/eslint.config.js b/eslint.config.js index ad6c438..4d251e2 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,13 +1,38 @@ -export default { - root: true, - parser: "@typescript-eslint/parser", - extends: "next/core-web-vitals", - overrides: [ - { - files: ["**/*.tsx"], - rules: { - "react-hooks/exhaustive-deps": "off", +import js from "@eslint/js"; +import nextPlugin from "@next/eslint-plugin-next"; +import tsParser from "@typescript-eslint/parser"; +import reactHooksPlugin from "eslint-plugin-react-hooks"; +import globals from "globals"; + +export default [ + js.configs.recommended, + { + files: ["**/*.{js,jsx,ts,tsx}"], + languageOptions: { + parser: tsParser, + globals: { + ...globals.browser, + ...globals.es2021, + ...globals.node, + React: "readonly", }, }, - ], -}; + plugins: { + "@next/next": nextPlugin, + "react-hooks": reactHooksPlugin, + }, + rules: { + "react-hooks/exhaustive-deps": "off", + "no-unused-vars": [ + "warn", + { + varsIgnorePattern: "^(NodeJS|other)$", + ignoreRestSiblings: true, + args: "none", + caughtErrors: "none", + }, + ], + ...nextPlugin.configs.recommended.rules, + }, + }, +]; diff --git a/next.config.ts b/next.config.ts index 4678774..e9ffa30 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,4 +1,7 @@ -/** @type {import('next').NextConfig} */ -const nextConfig = {}; +import type { NextConfig } from "next"; + +const nextConfig: NextConfig = { + /* config options here */ +}; export default nextConfig; diff --git a/package.json b/package.json index 881ec6c..d2d0edb 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "next-elysia-prisma", "version": "1.0.0", + "type": "module", "private": true, "scripts": { - "dev": "next dev", + "dev": "next dev --turbopack", "build": "next build", "start": "prisma migrate deploy && next start", "lint": "next lint", @@ -17,15 +18,15 @@ "elysia": "^1.1.25", "jose": "^5.9.6", "next": "15.0.3", - "react": "^18", - "react-dom": "^18" + "react": "19.0.0-rc-66855b96-20241106", + "react-dom": "19.0.0-rc-66855b96-20241106" }, "devDependencies": { "@types/bun": "^1.1.13", "@types/node": "^22.9.1", "@types/react": "^18", "@types/react-dom": "^18", - "eslint": "^8", + "eslint": "^9.15.0", "eslint-config-next": "15.0.3", "postcss": "^8", "prettier": "^3.3.3", @@ -34,4 +35,4 @@ "tailwindcss": "^3.4.15", "typescript": "^5" } -} \ No newline at end of file +} diff --git a/src/server/auth/index.ts b/src/server/auth/index.ts index 62072f8..9b19fb9 100644 --- a/src/server/auth/index.ts +++ b/src/server/auth/index.ts @@ -3,6 +3,7 @@ import prisma from "@/lib/prisma"; import { authUser } from "@/lib/typebox/auth"; import { serverEnv } from "@/utils/env/server"; import { Elysia, InternalServerError } from "elysia"; +import { ResponseCookie } from "next/dist/compiled/@edge-runtime/cookies"; import { cookies } from "next/headers"; /** @@ -54,12 +55,16 @@ export const authRoute = new Elysia({ prefix: "/auth" }) if (!user) throw new InternalServerError("User not found"); - (await cookies()).set({ + const cookie: ResponseCookie = { name: serverEnv.AUTH_COOKIE, value: (await encrypt(user))!, path: "/", httpOnly: true, maxAge: serverEnv.SEVEN_DAYS, + }; + + (await cookies()).set({ + ...cookie, }); return "success"; diff --git a/src/server/user/index.ts b/src/server/user/index.ts index ed14ab7..ac25a02 100644 --- a/src/server/user/index.ts +++ b/src/server/user/index.ts @@ -2,7 +2,7 @@ import { decrypt } from "@/lib/jwt"; import { serverEnv } from "@/utils/env/server"; import { User } from "@prisma/client"; import { Elysia, InternalServerError } from "elysia"; -import { cookies } from "next/headers"; +import { cookies, headers } from "next/headers"; /** * User route for retrieving the current user's information. @@ -13,12 +13,24 @@ export const userRoute = new Elysia({ prefix: "/user" }).get( "/me", async (ctx) => { // Decrypt user information from the authentication jwt cookie - const user = await decrypt( - (await cookies()).get(serverEnv.AUTH_COOKIE)?.value, - ); + try { + const cookieStore = await cookies(); + const allCookies = cookieStore.getAll(); + console.log( + "All cookies:", + (await headers()).count, + // Object.values((await headers()).toJSON()), + ); + const user = await decrypt( + (await cookies()).get(serverEnv.AUTH_COOKIE)?.value, + ); - if (!user) throw new InternalServerError("User not found"); + if (!user) throw new InternalServerError("User not found"); - return user; + return user; + } catch (error) { + console.error("Error:", error); + throw new InternalServerError("User not found"); + } }, ); diff --git a/tsconfig.json b/tsconfig.json index e7f92b4..d3bd61c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,7 @@ { "compilerOptions": { - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], + "target": "ES2017", + "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "strict": true, @@ -22,19 +19,9 @@ } ], "paths": { - "@/*": [ - "./src/*" - ] - }, - "target": "ES2017" + "@/*": ["./src/*"] + } }, - "include": [ - "next-env.d.ts", - "**/*.ts", - "**/*.tsx", - ".next/types/**/*.ts" - ], - "exclude": [ - "node_modules" - ] + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], + "exclude": ["node_modules"] }