nuxt-bearer-auth 0.1.5 → 0.1.7
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"), {
|
|
@@ -4633,7 +4633,7 @@ export declare function createBearerAuthSession<User extends BearerAuthUser>(eve
|
|
|
4633
4633
|
token: string;
|
|
4634
4634
|
refreshToken?: string | null;
|
|
4635
4635
|
profile?: User | null;
|
|
4636
|
-
}): Promise
|
|
4636
|
+
}): Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
4637
4637
|
export declare function updateBearerAuthSession<User extends BearerAuthUser>(event: H3Event, updates: Partial<Pick<BearerAuthSession<User>, "token" | "refreshToken" | "profile">>): Promise<boolean>;
|
|
4638
4638
|
export declare function getBearerAuthSession<User extends BearerAuthUser>(event: H3Event): Promise<BearerAuthSession<User> | null>;
|
|
4639
4639
|
export declare function destroyBearerAuthSession(event: H3Event): Promise<void>;
|
|
@@ -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 {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-bearer-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Reusable Nuxt authentication module for bearer-token APIs with Redis sessions and CSRF protection.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"build": "nuxt-module-build build",
|
|
40
40
|
"dev:prepare": "nuxt-module-build --stub",
|
|
41
41
|
"prepack": "nuxt-module-build build",
|
|
42
|
-
"typecheck": "vue-tsc --noEmit"
|
|
42
|
+
"typecheck": "vue-tsc --noEmit",
|
|
43
|
+
"test": "vitest run"
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
45
46
|
"defu": "^6.1.4",
|
|
@@ -51,11 +52,13 @@
|
|
|
51
52
|
"nuxt-csurf": "^1.6.5"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
55
|
+
"@nuxt/kit": "^3.12.0",
|
|
54
56
|
"@nuxt/module-builder": "^0.8.4",
|
|
55
57
|
"@nuxt/schema": "^3.12.0",
|
|
56
|
-
"@
|
|
58
|
+
"@types/node": "^26.2.0",
|
|
57
59
|
"nuxt": "^3.12.0",
|
|
58
60
|
"typescript": "^5.5.0",
|
|
61
|
+
"vitest": "^4.1.11",
|
|
59
62
|
"vue-tsc": "^2.0.0"
|
|
60
63
|
},
|
|
61
64
|
"packageManager": "npm@10.0.0"
|