@yassidev/nuxt-directus 0.0.20 → 0.0.22
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 +2 -2
- package/dist/runtime/client.js +19 -4
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1864,8 +1864,8 @@ function normalizeConfig(options, nuxt) {
|
|
|
1864
1864
|
types: { enabled: nuxt.options.dev, transform: [] },
|
|
1865
1865
|
proxy: { enabled: true, path: "/directus", options: {} },
|
|
1866
1866
|
image: { enabled: hasNuxtModule("@nuxt/image"), alias: "directus" },
|
|
1867
|
-
composables: { enabled: true, mode: "rest", client: true, server:
|
|
1868
|
-
auth: { enabled: true, mode: "
|
|
1867
|
+
composables: { enabled: true, mode: "rest", client: true, server: false },
|
|
1868
|
+
auth: { enabled: true, mode: "cookie", autoRefresh: true, cookieName: "auth_token" }
|
|
1869
1869
|
});
|
|
1870
1870
|
}
|
|
1871
1871
|
function setupComposables(config, nuxt, logger) {
|
package/dist/runtime/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NAME } from "./constants.js";
|
|
2
2
|
import { authentication, createDirectus, staticToken } from "@directus/sdk";
|
|
3
3
|
import { parseHost, joinURL } from "ufo";
|
|
4
|
-
import { createError, useRuntimeConfig } from "#imports";
|
|
4
|
+
import { createError, useCookie, useRuntimeConfig } from "#imports";
|
|
5
5
|
import { fetchTranslations } from "./server.js";
|
|
6
6
|
function getRuntimeConfig() {
|
|
7
7
|
if (import.meta.server) return useRuntimeConfig()[NAME];
|
|
@@ -21,14 +21,29 @@ export function createBaseDirectus() {
|
|
|
21
21
|
const instance = createDirectus(url, {
|
|
22
22
|
globals: {
|
|
23
23
|
fetch: $fetch.create({
|
|
24
|
-
|
|
25
|
-
onRequest({ options }) {
|
|
24
|
+
async onRequest({ options }) {
|
|
26
25
|
if (!auth?.cookieName) return;
|
|
27
|
-
const token =
|
|
26
|
+
const token = useCookie(auth.cookieName).value;
|
|
28
27
|
if (token) {
|
|
29
28
|
options.headers.set("Authorization", `Bearer ${token}`);
|
|
30
29
|
}
|
|
31
30
|
},
|
|
31
|
+
async onResponse({ response, options, request }) {
|
|
32
|
+
try {
|
|
33
|
+
if (!auth?.cookieName) return;
|
|
34
|
+
if (request.toString().endsWith("/auth/login")) {
|
|
35
|
+
const { mode } = JSON.parse(String(options.body));
|
|
36
|
+
if (mode === "cookie") {
|
|
37
|
+
const { access_token, expires } = response._data.data;
|
|
38
|
+
useCookie(auth.cookieName, {
|
|
39
|
+
expires: expires ? new Date(Date.now() + expires * 1e3) : void 0
|
|
40
|
+
}).value = access_token;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error("Error handling response:", error);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
32
47
|
onResponseError({ response }) {
|
|
33
48
|
const [error] = response._data.errors || [];
|
|
34
49
|
if (!error) return;
|