Refactor to accommodate authentication, transaction and pagination states together (#4636)

* fix: refactor to accommodate authentication, transaction and pagination together into ctx.state

* feat: allow passing response type to APIContext
This commit is contained in:
Apoorv Mishra
2023-01-04 23:51:44 +05:30
committed by GitHub
parent bb568d2e62
commit f4461573de
31 changed files with 753 additions and 675 deletions

View File

@@ -6,9 +6,10 @@ import Router from "koa-router";
import { AuthenticationError } from "@server/errors";
import auth from "@server/middlewares/authentication";
import { Collection, Team, View } from "@server/models";
import { AppState, AppContext, APIContext } from "@server/types";
import providers from "./providers";
const app = new Koa();
const app = new Koa<AppState, AppContext>();
const router = new Router();
router.use(passport.initialize());
@@ -20,8 +21,8 @@ providers.forEach((provider) => {
}
});
router.get("/redirect", auth(), async (ctx) => {
const { user } = ctx.state;
router.get("/redirect", auth(), async (ctx: APIContext) => {
const { user } = ctx.state.auth;
const jwtToken = user.getJwtToken();
if (jwtToken === ctx.params.token) {