altcha-lib 2.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,8 +55,7 @@ function create(options) {
55
55
  res.clearCookie(setCookie.name);
56
56
  }
57
57
  if (error && throwOnFailure) {
58
- res.status(403).json({ error });
59
- return;
58
+ throw Object.assign(new Error(error), { status: 403 });
60
59
  }
61
60
  next();
62
61
  });
@@ -14,7 +14,7 @@ export declare function create(options: AltchaOptions): {
14
14
  challengeHandler: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
15
15
  verifyHandler: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
16
16
  getPayloadFromRequest: (request: FastifyRequest, cookieName?: string) => Promise<string | undefined>;
17
- middleware: (options?: AltchaMiddlewareOptions) => (request: FastifyRequest, reply: FastifyReply) => Promise<undefined>;
17
+ middleware: (options?: AltchaMiddlewareOptions) => (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
18
18
  verify: typeof verify;
19
19
  };
20
20
  declare const _default: {
@@ -68,7 +68,7 @@ function create(options) {
68
68
  deleteCookie(reply, setCookie.name, setCookie.path);
69
69
  }
70
70
  if (error && throwOnFailure) {
71
- return reply.code(403).send({ error });
71
+ throw Object.assign(new Error(error), { statusCode: 403 });
72
72
  }
73
73
  };
74
74
  };
@@ -49,8 +49,7 @@ export function create(options) {
49
49
  res.clearCookie(setCookie.name);
50
50
  }
51
51
  if (error && throwOnFailure) {
52
- res.status(403).json({ error });
53
- return;
52
+ throw Object.assign(new Error(error), { status: 403 });
54
53
  }
55
54
  next();
56
55
  });
@@ -14,7 +14,7 @@ export declare function create(options: AltchaOptions): {
14
14
  challengeHandler: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
15
15
  verifyHandler: (request: FastifyRequest, reply: FastifyReply) => Promise<never>;
16
16
  getPayloadFromRequest: (request: FastifyRequest, cookieName?: string) => Promise<string | undefined>;
17
- middleware: (options?: AltchaMiddlewareOptions) => (request: FastifyRequest, reply: FastifyReply) => Promise<undefined>;
17
+ middleware: (options?: AltchaMiddlewareOptions) => (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
18
18
  verify: typeof verify;
19
19
  };
20
20
  declare const _default: {
@@ -62,7 +62,7 @@ export function create(options) {
62
62
  deleteCookie(reply, setCookie.name, setCookie.path);
63
63
  }
64
64
  if (error && throwOnFailure) {
65
- return reply.code(403).send({ error });
65
+ throw Object.assign(new Error(error), { statusCode: 403 });
66
66
  }
67
67
  };
68
68
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "altcha-lib",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
4
4
  "description": "A lightweight library for creating and verifying ALTCHA challenges on the server.",
5
5
  "author": {
6
6
  "name": "Daniel Regeci",