diff --git a/packages/server/src/middlewares/index.js b/packages/server/src/middlewares/index.js index f277d24d..d22af7db 100644 --- a/packages/server/src/middlewares/index.js +++ b/packages/server/src/middlewares/index.js @@ -1,6 +1,8 @@ // const fileUpload = require("@nanoexpress/middleware-file-upload/cjs")() export { default as withAuthentication } from "./withAuthentication" +export { default as withOptionalAuthentication } from "./withOptionalAuthentication" + export { default as errorHandler } from "./errorHandler" export { default as hasPermissions } from "./hasPermissions" export { default as roles } from "./roles" diff --git a/packages/server/src/middlewares/withOptionalAuthentication/index.js b/packages/server/src/middlewares/withOptionalAuthentication/index.js new file mode 100644 index 00000000..4a03cd05 --- /dev/null +++ b/packages/server/src/middlewares/withOptionalAuthentication/index.js @@ -0,0 +1,9 @@ +import withAuthentication from "../withAuthentication" + +export default (req, res, next) => { + if (req.headers?.authorization) { + withAuthentication(req, res, next) + } else { + next() + } +} \ No newline at end of file