Create JWT auth middleware and sample authenticated routes for /account
Changes:
- Create new middleware/auth.ts middleware to authenticate JWT
- Make vault.ts privateKey and publicKey fields to access them without await
- Remove @Service from auth router in auth-router.ts
- Create new AccountRouter with /account routes
Change-Id: Ie08651de7dbbce5d7596d80eba344707eb47d460
diff --git a/server/src/app.ts b/server/src/app.ts
index 04cf04b..2d4fd7d 100644
--- a/server/src/app.ts
+++ b/server/src/app.ts
@@ -15,23 +15,24 @@
* License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
-import express, { NextFunction, Request, Response } from 'express';
+import express, { json, NextFunction, Request, Response } from 'express';
import log from 'loglevel';
import { Service } from 'typedi';
import { StatusCode } from './constants.js';
-import { AuthRouter } from './routers/auth-router.js';
+import { accountRouter } from './routers/account-router.js';
+import { authRouter } from './routers/auth-router.js';
@Service()
export class App {
- constructor(private authRouter: AuthRouter) {}
-
async build() {
const app = express();
+ app.use(json());
+
// Setup routing
- const authRouter = await this.authRouter.build();
app.use('/auth', authRouter);
+ app.use('/account', accountRouter);
// Setup 404 error handling
app.use((_req, res) => {