nuxt-directus-sdk 3.0.2 → 3.0.3

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.mjs CHANGED
@@ -4,7 +4,7 @@ import { generateTypes } from '../dist/runtime/types/index.js';
4
4
  import { useUrl } from '../dist/runtime/utils/index.js';
5
5
 
6
6
  const name = "nuxt-directus-sdk";
7
- const version = "3.0.2";
7
+ const version = "3.0.3";
8
8
 
9
9
  const configKey = "directus";
10
10
  const logger = useLogger("nuxt-directus-sdk");
@@ -16,7 +16,7 @@ export interface DirectusAuth {
16
16
  expiresAt: number | null;
17
17
  }>;
18
18
  loginWithProvider: (provider: string, redirectOnLogin?: string) => Promise<void>;
19
- logout: () => Promise<void>;
19
+ logout: (redirect?: boolean | RouteLocationRaw) => Promise<void>;
20
20
  createUser: (data: Partial<DirectusUsers>) => Promise<DirectusUsers>;
21
21
  register: (data: Partial<DirectusUsers>) => Promise<DirectusUsers>;
22
22
  inviteUser: (email: string, role: string, inviteUrl?: string | undefined) => Promise<void>;
@@ -16,11 +16,6 @@ export function useDirectusAuth() {
16
16
  const loggedIn = computed(() => user.value !== null);
17
17
  async function readMe() {
18
18
  try {
19
- if (tokens.directusUrl.value !== config.public.directus.url) {
20
- tokens.directusUrl.value = config.public.directus.url;
21
- await logout();
22
- throw new Error("Directus URL changed");
23
- }
24
19
  if (!tokens.accessToken.value) {
25
20
  if (!tokens.refreshToken.value)
26
21
  throw new Error("No refresh token");
@@ -87,10 +82,9 @@ export function useDirectusAuth() {
87
82
  async function passwordReset(token, password) {
88
83
  return directus.request(directusPasswordReset(token, password));
89
84
  }
90
- async function logout() {
85
+ async function logout(redirect = true) {
91
86
  try {
92
87
  await directus.logout();
93
- await navigateTo(config.public.directus.auth?.redirect?.logout ?? config.public.directus.auth?.redirect?.home ?? "/");
94
88
  } finally {
95
89
  user.value = null;
96
90
  tokens.refreshToken.value = null;
@@ -98,6 +92,11 @@ export function useDirectusAuth() {
98
92
  tokens.expires.value = null;
99
93
  tokens.expiresAt.value = null;
100
94
  }
95
+ if (redirect) {
96
+ const defaultRedirect = config.public.directus.auth?.redirect?.logout ?? config.public.directus.auth?.redirect?.home ?? "/";
97
+ const redirectTo = typeof redirect === "boolean" ? defaultRedirect : redirect;
98
+ await navigateTo(redirectTo);
99
+ }
101
100
  }
102
101
  return {
103
102
  user,
@@ -15,7 +15,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
15
15
  if (!tokens.directusUrl.value || tokens.directusUrl.value !== config.public.directus.url) {
16
16
  tokens.directusUrl.value = config.public.directus.url;
17
17
  if (tokens.accessToken.value || tokens.refreshToken.value) {
18
- await directusAuth.logout();
18
+ await nuxtApp.runWithContext(async () => await directusAuth.logout(false));
19
19
  }
20
20
  }
21
21
  if (preview && token) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-directus-sdk",
3
3
  "type": "module",
4
- "version": "3.0.2",
4
+ "version": "3.0.3",
5
5
  "description": "A Directus nuxt module that uses the Directus SDK",
6
6
  "author": "Matthew Rollinson <matt@rolley.io>",
7
7
  "license": "MIT",