Skip to content

Commit

Permalink
need to think about components asap
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Sep 2, 2023
1 parent 28c01f5 commit f082660
Show file tree
Hide file tree
Showing 5 changed files with 751 additions and 1,093 deletions.
14 changes: 13 additions & 1 deletion service-node-koa/app/config/security/middleware.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { knex } from "../db/index.mjs";
import { verify } from "./encryption.mjs";

export const ifAdmin = async (ctx, next) => {
return await next();
Expand All @@ -9,7 +10,18 @@ export const ifOwner = async (ctx, next) => {
};

export const ifAuthenticated = async (ctx, next) => {
return await next();
const authHeader = ctx.request.header["authorization"];
if (!authHeader) ctx.throw(401, "Missing auth header");
const token = authHeader.replace("Bearer ", "");
try {
const details = verify(token);
if(!details.iat)
ctx.throw(401, "Something strange with this token", e);
// TODO more checks
return await next();
} catch (e) {
ctx.throw(401, "Something strange with this token", e);
}
};

export const contaOwnedBy = async (ctx, next) => {
Expand Down
2 changes: 1 addition & 1 deletion service-node-koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"start": "cross-env NODE_ENV=production node -r dotenv-flow/config index.mjs",
"dev:service": "cross-env NODE_ENV=development nodemon -r dotenv-flow/config",
"test": "cross-env NODE_ENV=test mocha -r dotenv-flow/config -r app/config/_test_hooks.mjs --recursive **/*.spec.mjs",
"test": "cross-env NODE_ENV=test mocha -r dotenv-flow/config -r app/config/_test_hooks.mjs --recursive app/**/*.spec.mjs",
"test:coverage": "c8 npm run test",
"migrate:make": "knex migrate:make --knexfile app/config/db/knexfile.cjs -x mjs -- ",
"migrate:latest": "knex migrate:latest --knexfile app/config/db/knexfile.cjs",
Expand Down
Loading

0 comments on commit f082660

Please sign in to comment.