From 8c60fa731c43f2ad1e1a07d12707c8390436d652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Ar=C3=A9jula?= Date: Thu, 4 Apr 2024 16:50:33 +0000 Subject: [PATCH] Remove jose dependency and commented code --- playbeat/package-lock.json | 9 ------ playbeat/package.json | 1 - playbeat/src/middleware.ts | 56 ++------------------------------------ 3 files changed, 3 insertions(+), 63 deletions(-) diff --git a/playbeat/package-lock.json b/playbeat/package-lock.json index bc92a84..6f8cf31 100644 --- a/playbeat/package-lock.json +++ b/playbeat/package-lock.json @@ -23,7 +23,6 @@ "axios": "^1.6.8", "clsx": "^2.1.0", "framer-motion": "^11.0.5", - "jose": "^5.2.3", "react": "^18.2.0", "react-dom": "^18.2.0", "svelte": "^4.2.12", @@ -6922,14 +6921,6 @@ "jiti": "bin/jiti.js" } }, - "node_modules/jose": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/jose/-/jose-5.2.3.tgz", - "integrity": "sha512-KUXdbctm1uHVL8BYhnyHkgp3zDX5KW8ZhAKVFEfUbU2P8Alpzjb+48hHvjOdQIyPshoblhzsuqOwEEAbtHVirA==", - "funding": { - "url": "https://github.com/sponsors/panva" - } - }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/playbeat/package.json b/playbeat/package.json index 3736b1c..c8b04cd 100644 --- a/playbeat/package.json +++ b/playbeat/package.json @@ -25,7 +25,6 @@ "axios": "^1.6.8", "clsx": "^2.1.0", "framer-motion": "^11.0.5", - "jose": "^5.2.3", "react": "^18.2.0", "react-dom": "^18.2.0", "svelte": "^4.2.12", diff --git a/playbeat/src/middleware.ts b/playbeat/src/middleware.ts index 3af77b6..f0a315b 100644 --- a/playbeat/src/middleware.ts +++ b/playbeat/src/middleware.ts @@ -1,36 +1,11 @@ -import { errors, jwtVerify } from "jose"; + import { defineMiddleware } from "astro/middleware"; import { TOKEN, PUBLIC_ROUTES } from "./constants"; // The JWT secret -const secret = new TextEncoder().encode(import.meta.env.JWT_SECRET_KEY); +// const secret = new TextEncoder().encode(import.meta.env.JWT_SECRET_KEY); -/** -* Verify if the client token is valid. -*/ -const verifyAuth = async (token?: string) => { - if (!token) { - return { - status: "unauthorized", - msg: "Please pass a request token", - } as const; - } - try { - const jwtVerifyResult = await jwtVerify(token, secret); - - return { - status: "authorized", - payload: jwtVerifyResult.payload, - msg: "successfully verified auth token", - } as const; - } catch (err) { - if (err instanceof errors.JOSEError) { - return { status: "error", msg: err.message } as const; - } - return { status: "error", msg: "could not validate auth token" } as const; - } -}; export const onRequest = defineMiddleware(async (context, next) => { // Ignore auth validation for public routes @@ -49,30 +24,5 @@ export const onRequest = defineMiddleware(async (context, next) => { }else { return Response.redirect(new URL("/", context.url)); } - // const validationResult = await verifyAuth(token); - - - - // Handle the validation result - // switch (validationResult.status) { - // case "authorized": - // // Respond as usual if the user is authorised - // return next(); - - // case "error": - // case "unauthorized": - // // If an API endpoint, return a JSON response - // if (context.url.pathname.startsWith("/api/")) { - // return new Response(JSON.stringify({ message: validationResult.msg }), { - // status: 401, - // }); - // } - // // Otherwise, this is a standard page. Redirect to the root page for the user to login - // else { - // return Response.redirect(new URL("/", context.url)); - // } - - // default: - // return Response.redirect(new URL("/", context.url)); - // } + }); \ No newline at end of file