@michael-nussbaumer/nuxt-directus 0.2.5 → 0.2.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
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0 || ^4.0.0"
6
6
  },
7
- "version": "0.2.5",
7
+ "version": "0.2.7",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -169,6 +169,10 @@ export const useDirectusAuth = () => {
169
169
  return true;
170
170
  } catch (e) {
171
171
  error.value = e.message || "Token refresh failed";
172
+ const refreshTokenCookie = useCookie("directus_refresh_token");
173
+ refreshTokenCookie.value = null;
174
+ const dataCookie = useCookie("directus-data");
175
+ dataCookie.value = null;
172
176
  throw e;
173
177
  } finally {
174
178
  isLoading.value = false;
@@ -78,8 +78,17 @@ export default defineNuxtPlugin(async () => {
78
78
  }
79
79
  return me;
80
80
  } catch (error) {
81
+ if (import.meta.dev) {
82
+ console.log("[Directus] Authentication failed:", error);
83
+ }
81
84
  isAuthenticatedState.value = false;
82
85
  currentUser.value = null;
86
+ if (import.meta.client) {
87
+ const refreshTokenCookie = useCookie("directus_refresh_token");
88
+ refreshTokenCookie.value = null;
89
+ const dataCookie = useCookie("directus-data");
90
+ dataCookie.value = null;
91
+ }
83
92
  return false;
84
93
  }
85
94
  };
@@ -1,8 +1,9 @@
1
- import { defineNuxtRouteMiddleware, navigateTo, useRuntimeConfig, useCookie } from "#app";
1
+ import { defineNuxtRouteMiddleware, navigateTo, useRuntimeConfig, useCookie, useNuxtApp } from "#app";
2
2
  import { useDirectusAuth } from "../composables/useDirectusAuth.js";
3
3
  export default defineNuxtRouteMiddleware(async (to, from) => {
4
- const { isAuthenticated, fetchUser } = useDirectusAuth();
4
+ const { isAuthenticated } = useDirectusAuth();
5
5
  const config = useRuntimeConfig();
6
+ const { $directusAuth } = useNuxtApp();
6
7
  const { loginPath, registerPath, afterLoginPath } = config.public.directus?.auth || {
7
8
  loginPath: "/login",
8
9
  registerPath: "/register",
@@ -33,12 +34,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
33
34
  return;
34
35
  }
35
36
  try {
36
- if (!isAuthenticated.value) {
37
- try {
38
- await fetchUser();
39
- } catch {
40
- }
41
- }
37
+ await $directusAuth.checkAuthStatus();
42
38
  const authenticated = isAuthenticated.value;
43
39
  if (!authenticated) {
44
40
  if (authMeta?.unauthenticatedOnly) {
@@ -72,7 +68,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
72
68
  }
73
69
  const permissionsConfig = config.public.directus?.auth?.permissions;
74
70
  if (permissionsConfig?.enabled && (authMeta?.roles || authMeta?.excludeRoles)) {
75
- const currentUser = isAuthenticated.value ? await fetchUser() : null;
71
+ const currentUser = $directusAuth.currentUser.value;
76
72
  if (currentUser) {
77
73
  const roleField = permissionsConfig.field || "role";
78
74
  let userRoleValue = currentUser[roleField];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michael-nussbaumer/nuxt-directus",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Nuxt 4 module for Directus SDK with auth and TypeScript type generation",
5
5
  "license": "MIT",
6
6
  "type": "module",