@wpnuxt/auth 2.0.0-alpha.2 → 2.0.0-alpha.4
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 +1 -1
- package/dist/module.mjs +3 -2
- package/dist/runtime/composables/useWPAuth.js +6 -5
- package/dist/runtime/server/api/auth/oauth/callback.get.js +3 -2
- package/dist/runtime/server/api/auth/provider/[provider]/authorize.get.js +3 -2
- package/dist/runtime/server/api/auth/provider/[provider]/callback.get.js +3 -2
- package/dist/runtime/server/utils/logger.d.ts +0 -0
- package/dist/runtime/server/utils/logger.js +2 -0
- package/dist/runtime/utils/logger.d.ts +0 -0
- package/dist/runtime/utils/logger.js +2 -0
- package/package.json +2 -2
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, cpSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { defineNuxtModule, createResolver, addPlugin, addImports, addServerHandler } from '@nuxt/kit';
|
|
3
|
+
import { defineNuxtModule, createResolver, addPlugin, addImports, addServerHandler, useLogger } from '@nuxt/kit';
|
|
4
4
|
|
|
5
5
|
function detectAuthCapabilities(schemaPath) {
|
|
6
6
|
if (!existsSync(schemaPath)) {
|
|
@@ -224,11 +224,12 @@ const module$1 = defineNuxtModule({
|
|
|
224
224
|
path: resolver.resolve("./runtime/types/index.ts")
|
|
225
225
|
});
|
|
226
226
|
});
|
|
227
|
+
const logger = useLogger("wpnuxt:auth");
|
|
227
228
|
const providers = [];
|
|
228
229
|
if (passwordEnabled) providers.push("password");
|
|
229
230
|
if (oauthEnabled) providers.push("oauth");
|
|
230
231
|
if (headlessLoginEnabled) providers.push("headlessLogin");
|
|
231
|
-
|
|
232
|
+
logger.info(`Module loaded (providers: ${providers.join(", ") || "none"})`);
|
|
232
233
|
}
|
|
233
234
|
});
|
|
234
235
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { computed, useState, useCookie, useRuntimeConfig, navigateTo, useGraphqlMutation } from "#imports";
|
|
2
|
+
import { logger } from "../utils/logger.js";
|
|
2
3
|
export function useWPAuth() {
|
|
3
4
|
const config = useRuntimeConfig().public.wpNuxtAuth;
|
|
4
5
|
const authState = useState("wpnuxt-auth", () => ({
|
|
@@ -113,7 +114,7 @@ export function useWPAuth() {
|
|
|
113
114
|
async function loginWithOAuth() {
|
|
114
115
|
const providers = getProviders();
|
|
115
116
|
if (!providers.oauth) {
|
|
116
|
-
|
|
117
|
+
logger.warn("OAuth is not enabled");
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
119
120
|
await navigateTo("/api/auth/oauth/authorize", { external: true });
|
|
@@ -136,7 +137,7 @@ export function useWPAuth() {
|
|
|
136
137
|
const wordpressUrl = runtimeConfig.public.wordpressUrl;
|
|
137
138
|
const graphqlEndpoint = runtimeConfig.public.wpNuxt?.graphqlEndpoint || "/graphql";
|
|
138
139
|
if (!wordpressUrl) {
|
|
139
|
-
|
|
140
|
+
logger.warn("WordPress URL not configured");
|
|
140
141
|
return [];
|
|
141
142
|
}
|
|
142
143
|
const response = await $fetch(`${wordpressUrl}${graphqlEndpoint}`, {
|
|
@@ -156,7 +157,7 @@ export function useWPAuth() {
|
|
|
156
157
|
}
|
|
157
158
|
});
|
|
158
159
|
if (response.errors?.length) {
|
|
159
|
-
|
|
160
|
+
logger.warn("Failed to fetch login clients:", response.errors[0]?.message);
|
|
160
161
|
return [];
|
|
161
162
|
}
|
|
162
163
|
const clients = response.data?.loginClients || [];
|
|
@@ -169,13 +170,13 @@ export function useWPAuth() {
|
|
|
169
170
|
isEnabled: client.isEnabled
|
|
170
171
|
}));
|
|
171
172
|
} catch (error) {
|
|
172
|
-
|
|
173
|
+
logger.warn("Failed to fetch login providers:", error);
|
|
173
174
|
return [];
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
async function loginWithProvider(provider) {
|
|
177
178
|
if (!hasHeadlessLoginAuth()) {
|
|
178
|
-
|
|
179
|
+
logger.warn("Headless Login is not enabled");
|
|
179
180
|
return;
|
|
180
181
|
}
|
|
181
182
|
await navigateTo(`/api/auth/provider/${provider.toLowerCase()}/authorize`, { external: true });
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, getCookie, setCookie, deleteCookie, sendRedirect, createError, getRequestURL } from "h3";
|
|
2
2
|
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import { logger } from "../../../utils/logger.js";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
5
|
const query = getQuery(event);
|
|
5
6
|
const config = useRuntimeConfig();
|
|
@@ -42,7 +43,7 @@ export default defineEventHandler(async (event) => {
|
|
|
42
43
|
client_secret: privateConfig.clientSecret
|
|
43
44
|
}).toString()
|
|
44
45
|
}).catch((error) => {
|
|
45
|
-
|
|
46
|
+
logger.error("Token exchange failed:", error);
|
|
46
47
|
throw createError({ statusCode: 500, message: "Failed to exchange authorization code" });
|
|
47
48
|
});
|
|
48
49
|
if (!tokenResponse.access_token) {
|
|
@@ -54,7 +55,7 @@ export default defineEventHandler(async (event) => {
|
|
|
54
55
|
Authorization: `Bearer ${tokenResponse.access_token}`
|
|
55
56
|
}
|
|
56
57
|
}).catch((error) => {
|
|
57
|
-
|
|
58
|
+
logger.error("User info fetch failed:", error);
|
|
58
59
|
return null;
|
|
59
60
|
});
|
|
60
61
|
const isProduction = process.env.NODE_ENV === "production";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getRouterParam, setCookie, sendRedirect, createError, getRequestURL } from "h3";
|
|
2
2
|
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import { logger } from "../../../../utils/logger.js";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
5
|
const provider = getRouterParam(event, "provider");
|
|
5
6
|
if (!provider) {
|
|
@@ -31,11 +32,11 @@ export default defineEventHandler(async (event) => {
|
|
|
31
32
|
`
|
|
32
33
|
}
|
|
33
34
|
}).catch((error) => {
|
|
34
|
-
|
|
35
|
+
logger.error("Failed to fetch login clients:", error);
|
|
35
36
|
throw createError({ statusCode: 500, message: "Failed to fetch login providers from WordPress" });
|
|
36
37
|
});
|
|
37
38
|
if (response.errors?.length) {
|
|
38
|
-
|
|
39
|
+
logger.error("GraphQL errors:", response.errors);
|
|
39
40
|
throw createError({ statusCode: 500, message: response.errors[0]?.message || "GraphQL error" });
|
|
40
41
|
}
|
|
41
42
|
const loginClients = response.data?.loginClients || [];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, getRouterParam, getCookie, setCookie, deleteCookie, sendRedirect, createError } from "h3";
|
|
2
2
|
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import { logger } from "../../../../utils/logger.js";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
5
|
const query = getQuery(event);
|
|
5
6
|
const routeProvider = getRouterParam(event, "provider");
|
|
@@ -80,11 +81,11 @@ export default defineEventHandler(async (event) => {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
}).catch((error) => {
|
|
83
|
-
|
|
84
|
+
logger.error("Login mutation failed:", error);
|
|
84
85
|
throw createError({ statusCode: 500, message: "Failed to authenticate with WordPress" });
|
|
85
86
|
});
|
|
86
87
|
if (response.errors?.length) {
|
|
87
|
-
|
|
88
|
+
logger.error("GraphQL errors:", response.errors);
|
|
88
89
|
throw createError({ statusCode: 400, message: response.errors[0]?.message || "Authentication failed" });
|
|
89
90
|
}
|
|
90
91
|
const loginData = response.data?.login;
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wpnuxt/auth",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.4",
|
|
4
4
|
"description": "Authentication module for WPNuxt using WPGraphQL JWT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"nuxt": "^4.0.0",
|
|
48
|
-
"@wpnuxt/core": "2.0.0-alpha.
|
|
48
|
+
"@wpnuxt/core": "2.0.0-alpha.4"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "nuxt-module-build build",
|