@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "directus",
3
3
  "configKey": "directus",
4
- "version": "0.0.20",
4
+ "version": "0.0.22",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
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: true },
1868
- auth: { enabled: true, mode: "session", autoRefresh: true, cookieName: "directus_session_token" }
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) {
@@ -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
- baseURL: url,
25
- onRequest({ options }) {
24
+ async onRequest({ options }) {
26
25
  if (!auth?.cookieName) return;
27
- const token = toValue(useCookie(auth.cookieName));
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yassidev/nuxt-directus",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "A Nuxt module for better integration with Directus CMS.",
5
5
  "repository": "yassilah/nuxt-directus",
6
6
  "license": "MIT",