Skip to content

Commit

Permalink
Remove jose dependency and commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
Arejula11 committed Apr 4, 2024
1 parent 1ff1bd9 commit 8c60fa7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 63 deletions.
9 changes: 0 additions & 9 deletions playbeat/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion playbeat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 3 additions & 53 deletions playbeat/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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));
// }

});

0 comments on commit 8c60fa7

Please sign in to comment.