@vivinkv28/strapi-2fa-admin-plugin 0.1.13 → 0.1.14
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.
- package/dist/server/index.js +13 -3
- package/dist/server/index.mjs +13 -3
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -77,13 +77,23 @@ const getService = () => strapi.plugin("admin-2fa").service("auth");
|
|
|
77
77
|
const APPLICATION_ERROR_STATUS = {
|
|
78
78
|
ApplicationError: 400,
|
|
79
79
|
ValidationError: 400,
|
|
80
|
-
UnauthorizedError:
|
|
81
|
-
ForbiddenError:
|
|
80
|
+
UnauthorizedError: 400,
|
|
81
|
+
ForbiddenError: 400,
|
|
82
82
|
NotFoundError: 404,
|
|
83
83
|
PayloadTooLargeError: 413,
|
|
84
84
|
RateLimitError: 429,
|
|
85
85
|
NotImplementedError: 501
|
|
86
86
|
};
|
|
87
|
+
const deriveApplicationErrorStatus = (error2) => {
|
|
88
|
+
if (typeof error2?.status === "number" && error2.status >= 400 && error2.status < 500) {
|
|
89
|
+
return error2.status;
|
|
90
|
+
}
|
|
91
|
+
const message = typeof error2?.message === "string" ? error2.message.toLowerCase() : "";
|
|
92
|
+
if (message.includes("session not found") || message.includes("please log in again") || message.includes("otp expired") || message.includes("expired otp")) {
|
|
93
|
+
return 409;
|
|
94
|
+
}
|
|
95
|
+
return APPLICATION_ERROR_STATUS[error2?.name] ?? 400;
|
|
96
|
+
};
|
|
87
97
|
const setRefreshCookie = (ctx, refreshToken, cookieOptions) => {
|
|
88
98
|
ctx.cookies.set(sessionAuth$1.REFRESH_COOKIE_NAME, refreshToken, cookieOptions);
|
|
89
99
|
};
|
|
@@ -98,7 +108,7 @@ const getClientIp = (ctx) => {
|
|
|
98
108
|
return String(ctx.request.ip ?? ctx.ip ?? "").trim();
|
|
99
109
|
};
|
|
100
110
|
const sendApplicationError = (ctx, error2) => {
|
|
101
|
-
const derivedStatus =
|
|
111
|
+
const derivedStatus = deriveApplicationErrorStatus(error2);
|
|
102
112
|
ctx.status = derivedStatus;
|
|
103
113
|
ctx.body = {
|
|
104
114
|
data: null,
|
package/dist/server/index.mjs
CHANGED
|
@@ -63,13 +63,23 @@ const getService = () => strapi.plugin("admin-2fa").service("auth");
|
|
|
63
63
|
const APPLICATION_ERROR_STATUS = {
|
|
64
64
|
ApplicationError: 400,
|
|
65
65
|
ValidationError: 400,
|
|
66
|
-
UnauthorizedError:
|
|
67
|
-
ForbiddenError:
|
|
66
|
+
UnauthorizedError: 400,
|
|
67
|
+
ForbiddenError: 400,
|
|
68
68
|
NotFoundError: 404,
|
|
69
69
|
PayloadTooLargeError: 413,
|
|
70
70
|
RateLimitError: 429,
|
|
71
71
|
NotImplementedError: 501
|
|
72
72
|
};
|
|
73
|
+
const deriveApplicationErrorStatus = (error2) => {
|
|
74
|
+
if (typeof error2?.status === "number" && error2.status >= 400 && error2.status < 500) {
|
|
75
|
+
return error2.status;
|
|
76
|
+
}
|
|
77
|
+
const message = typeof error2?.message === "string" ? error2.message.toLowerCase() : "";
|
|
78
|
+
if (message.includes("session not found") || message.includes("please log in again") || message.includes("otp expired") || message.includes("expired otp")) {
|
|
79
|
+
return 409;
|
|
80
|
+
}
|
|
81
|
+
return APPLICATION_ERROR_STATUS[error2?.name] ?? 400;
|
|
82
|
+
};
|
|
73
83
|
const setRefreshCookie = (ctx, refreshToken, cookieOptions) => {
|
|
74
84
|
ctx.cookies.set(sessionAuth$1.REFRESH_COOKIE_NAME, refreshToken, cookieOptions);
|
|
75
85
|
};
|
|
@@ -84,7 +94,7 @@ const getClientIp = (ctx) => {
|
|
|
84
94
|
return String(ctx.request.ip ?? ctx.ip ?? "").trim();
|
|
85
95
|
};
|
|
86
96
|
const sendApplicationError = (ctx, error2) => {
|
|
87
|
-
const derivedStatus =
|
|
97
|
+
const derivedStatus = deriveApplicationErrorStatus(error2);
|
|
88
98
|
ctx.status = derivedStatus;
|
|
89
99
|
ctx.body = {
|
|
90
100
|
data: null,
|