Skip to content

Commit

Permalink
rename the user object to auth
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Apr 18, 2024
1 parent 0471fe7 commit 6fffe05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/server/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,18 @@ export class Dispatcher {

// eslint-disable-next-line sonarjs/cognitive-complexity, max-statements
public async request({
auth,
body,
headers = {},
method,
path,
query,
req,
user,
}: {
auth?: {
password?: string;
username?: string;
};
body: unknown;
headers: {
[key: string]: string;
Expand All @@ -240,10 +244,6 @@ export class Dispatcher {
req: {
path?: string;
};
user?: {
password?: string;
username?: string;
};
}): Promise<NormalizedCounterfactResponseObject> {
debug(`request: ${method} ${path}`);

Expand All @@ -264,8 +264,10 @@ export class Dispatcher {
path,
this.parameterTypes(operation?.parameters),
)({
auth,
body,
context: this.contextRegistry.find(matchedPath),

headers,

proxy: async (url: string) => {
Expand Down Expand Up @@ -301,8 +303,6 @@ export class Dispatcher {
response: createResponseBuilder(operation ?? { responses: {} }),

tools: new Tools({ headers }),

user,
});

Check warning on line 306 in src/server/dispatcher.ts

View workflow job for this annotation

GitHub Actions / CI Checks (ubuntu-latest)

[max-lines] File has too many lines (334). Maximum allowed is 305.

if (response === undefined) {
Expand Down
6 changes: 3 additions & 3 deletions src/server/koa-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function addCors(ctx: Koa.ExtendableContext, headers?: IncomingHttpHeaders) {
ctx.set("Access-Control-Allow-Credentials", "true");
}

function getBasicAuthCredentials(
function getAuthObject(
ctx: Koa.ExtendableContext & { user?: { [key: string]: string } },
):
| {
Expand Down Expand Up @@ -60,7 +60,7 @@ export function koaMiddleware(
return await next();
}

const user = getBasicAuthCredentials(ctx);
const auth = getAuthObject(ctx);

/* @ts-expect-error the body comes from koa-bodyparser, not sure how to fix this */
const { body, headers, query } = ctx.request;
Expand All @@ -84,6 +84,7 @@ export function koaMiddleware(
}

const response = await dispatcher.request({
auth,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
body,
/* @ts-expect-error the value of a header can be an array and we don't have a solution for that yet */
Expand All @@ -93,7 +94,6 @@ export function koaMiddleware(
/* @ts-expect-error the value of a querystring item can be an array and we don't have a solution for that yet */
query,
req: { path: "", ...ctx.req },
user,
});

/* eslint-disable require-atomic-updates */
Expand Down
4 changes: 2 additions & 2 deletions test/server/koa-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ describe("koa middleware", () => {
const registry = new Registry();

registry.add("/hello", {
GET({ user }: { user?: { password?: string; username?: string } }) {
GET({ auth }: { auth?: { password?: string; username?: string } }) {
return {
body: `${user?.username ?? ""} / ${user?.password ?? ""}`,
body: `${auth?.username ?? ""} / ${auth?.password ?? ""}`,
};
},
});
Expand Down

0 comments on commit 6fffe05

Please sign in to comment.