nuxt-bearer-auth 0.1.5 → 0.1.6
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/module.json
CHANGED
|
@@ -10,10 +10,33 @@ import { createBearerAuthSession } from "../../utils/sessions.js";
|
|
|
10
10
|
export default defineEventHandler(async (event) => {
|
|
11
11
|
try {
|
|
12
12
|
const body = await readBody(event);
|
|
13
|
-
if (!body
|
|
13
|
+
if (!body || typeof body !== "object" || Object.keys(body).length === 0) {
|
|
14
14
|
throw createError({
|
|
15
15
|
statusCode: 422,
|
|
16
|
-
statusMessage: "
|
|
16
|
+
statusMessage: "Login credentials are required"
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const hasCustomIdentifier = Object.keys(body).some(
|
|
20
|
+
(key) => key !== "password" && key !== "pass" && key !== "remember" && key !== "rememberMe" && Boolean(body[key])
|
|
21
|
+
);
|
|
22
|
+
const identifier = body.identifier ?? body.email ?? body.username ?? body.phone ?? body.mobile ?? body.phone_number ?? (hasCustomIdentifier ? true : void 0);
|
|
23
|
+
const password = body.password ?? body.pass;
|
|
24
|
+
if (!identifier && !password) {
|
|
25
|
+
throw createError({
|
|
26
|
+
statusCode: 422,
|
|
27
|
+
statusMessage: "Login credentials are required. Provide an identifier (e.g. email, username, phone, mobile, or identifier) and a password."
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (!identifier) {
|
|
31
|
+
throw createError({
|
|
32
|
+
statusCode: 422,
|
|
33
|
+
statusMessage: "Login identifier is required (e.g. email, username, phone, mobile, or identifier)."
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (!password) {
|
|
37
|
+
throw createError({
|
|
38
|
+
statusCode: 422,
|
|
39
|
+
statusMessage: "Password is required."
|
|
17
40
|
});
|
|
18
41
|
}
|
|
19
42
|
const response = await callAuthApi(getAuthEndpoint("login"), {
|
|
@@ -6,10 +6,30 @@ import { createBearerAuthSession } from "../../utils/sessions.js";
|
|
|
6
6
|
export default defineEventHandler(async (event) => {
|
|
7
7
|
try {
|
|
8
8
|
const body = await readBody(event);
|
|
9
|
-
if (!body
|
|
9
|
+
if (!body || typeof body !== "object" || Object.keys(body).length === 0) {
|
|
10
10
|
throw createError({
|
|
11
11
|
statusCode: 422,
|
|
12
|
-
statusMessage: "OTP
|
|
12
|
+
statusMessage: "OTP verification credentials are required"
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const otp = body.otp ?? body.code;
|
|
16
|
+
const identifier = body.identifier ?? body.email ?? body.phone ?? body.mobile ?? body.username ?? body.phone_number;
|
|
17
|
+
if (!otp && !identifier) {
|
|
18
|
+
throw createError({
|
|
19
|
+
statusCode: 422,
|
|
20
|
+
statusMessage: "OTP code and identifier (e.g. email, phone, mobile, username, or identifier) are required."
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (!otp) {
|
|
24
|
+
throw createError({
|
|
25
|
+
statusCode: 422,
|
|
26
|
+
statusMessage: "OTP code is required."
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (!identifier) {
|
|
30
|
+
throw createError({
|
|
31
|
+
statusCode: 422,
|
|
32
|
+
statusMessage: "Identifier is required for OTP verification (e.g. email, phone, mobile, username, or identifier)."
|
|
13
33
|
});
|
|
14
34
|
}
|
|
15
35
|
const response = await callAuthApi(getAuthEndpoint("verifyOtp"), {
|
|
@@ -33,8 +33,12 @@ export interface AuthApiResponse<T = unknown> {
|
|
|
33
33
|
nextAction?: string;
|
|
34
34
|
}
|
|
35
35
|
export interface LoginCredentials {
|
|
36
|
-
identifier
|
|
37
|
-
|
|
36
|
+
identifier?: string;
|
|
37
|
+
email?: string;
|
|
38
|
+
username?: string;
|
|
39
|
+
phone?: string;
|
|
40
|
+
mobile?: string;
|
|
41
|
+
password?: string;
|
|
38
42
|
[key: string]: unknown;
|
|
39
43
|
}
|
|
40
44
|
export interface SocialLoginCredentials {
|