Skip to content

Commit

Permalink
Workaround for upgraded elysia derive for public route /swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
cham11ng committed Aug 28, 2024
1 parent 5a55992 commit b1c943e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
mongodb:
image: "mongo:latest"
Expand Down
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bun-api-starter",
"version": "1.2.0",
"version": "1.3.0",
"scripts": {
"test": "NODE_ENV=test bun test ./test/**.test.ts",
"dev": "bun run --watch src/app.ts",
Expand All @@ -10,27 +10,29 @@
"lint:fix": "eslint src test --fix"
},
"dependencies": {
"@elysiajs/cors": "^1.0.2",
"@elysiajs/jwt": "^1.0.2",
"@elysiajs/swagger": "^1.0.4",
"elysia": "^1.0.14",
"@elysiajs/cors": "^1.1.0",
"@elysiajs/jwt": "^1.1.0",
"@elysiajs/swagger": "^1.1.1",
"elysia": "^1.1.8",
"http-status-codes": "^2.3.0",
"mongoose": "^8.3.2",
"yoctocolors": "^2.0.0"
"mongoose": "^8.5.4",
"yoctocolors": "^2.1.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"bun-types": "^1.1.4",
"eslint": "^8.57.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.9.1",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"bun-types": "^1.1.26",
"eslint": "^9.9.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsdoc": "^48.2.3",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-sonarjs": "^0.25.1",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5"
"eslint-plugin-jsdoc": "^50.2.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-sonarjs": "^2.0.1",
"husky": "^9.1.5",
"lint-staged": "^15.2.9",
"prettier": "^3.3.3"
},
"lint-staged": {
"*.{js,ts}": [
Expand Down
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ db.connect();

app
.use(loggerPlugin)
.use(securityPlugin)
.use(errorPlugin)
.use(
swagger({
path: '/docs',
Expand All @@ -28,6 +26,8 @@ app
}
})
)
.use(securityPlugin)
.use(errorPlugin)
.get('/', () => ({
name: config.app.name,
version: config.app.version
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import UnauthorizedError from '../domain/exceptions/UnauthorizedError';

export default (app: Elysia) =>
// @ts-expect-error This remains valid after JWT is implemented.
app.derive(async ({ jwt, headers: { authorization } }) => {
const user = await jwt.verify(authorization?.split(' ')[1]);
app.derive(async ({ jwt, headers, request }) => {
// TODO: Fix me later.
if (request.url.includes('/docs')) {
return;
}

const user = await jwt.verify(headers.authorization?.split(' ')[1]);

if (!user) {
throw new UnauthorizedError('Invalid token!');
Expand Down

0 comments on commit b1c943e

Please sign in to comment.