Skip to content

Commit

Permalink
Add request to strategy callback (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
maou-shonen authored Apr 26, 2024
1 parent a50351e commit 1b2d6e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface FormStrategyVerifyParams {
* server's `getLoadContext()` function.
*/
context?: AppLoadContext;
/**
* The request that triggered the authentication.
*/
request: Request;
}

export class FormStrategy<User> extends Strategy<
Expand All @@ -30,7 +34,7 @@ export class FormStrategy<User> extends Strategy<
let form = await this.readFormData(request, options);

try {
let user = await this.verify({ form, context: options.context });
let user = await this.verify({ form, context: options.context, request });
return this.success(user, request, sessionStorage, options);
} catch (error) {
if (error instanceof Error) {
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe(FormStrategy, () => {

await strategy.authenticate(request, sessionStorage, BASE_OPTIONS);

expect(verify).toBeCalledWith({ form: body });
expect(verify).toBeCalledWith({ form: body, request });
});

test("should return what the verify callback returned", async () => {
Expand Down Expand Up @@ -76,7 +76,7 @@ describe(FormStrategy, () => {
context,
});

expect(verify).toBeCalledWith({ form: body, context });
expect(verify).toBeCalledWith({ form: body, context, request });
});

test("should prefer context.formData over request.formData()", async () => {
Expand Down

0 comments on commit 1b2d6e7

Please sign in to comment.