nuxt-auth-kit 1.0.3 → 1.0.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 CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0 || ^4.0.0"
6
6
  },
7
- "version": "1.0.3",
7
+ "version": "1.0.4",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -1,7 +1,8 @@
1
- import { useRuntimeConfig, navigateTo, useCookie } from "#app";
1
+ import { useNuxtApp, useRuntimeConfig, navigateTo, useCookie } from "#app";
2
2
  import { useAuthStore } from "../stores/auth.js";
3
3
  export function useAuth() {
4
- const store = useAuthStore();
4
+ const nuxtApp = useNuxtApp();
5
+ const store = useAuthStore(nuxtApp.$pinia);
5
6
  const config = useRuntimeConfig();
6
7
  const opts = config.public.nuxtAuthKit;
7
8
  const apiBase = opts?.apiBase || "";
@@ -1,20 +1,25 @@
1
1
  import { defineNuxtPlugin, useCookie, useRuntimeConfig } from "#app";
2
2
  import { useAuthStore } from "../stores/auth.js";
3
3
  import { useAuth } from "../composables/useAuth.js";
4
- export default defineNuxtPlugin(async (nuxtApp) => {
5
- const store = useAuthStore();
6
- const config = useRuntimeConfig();
7
- const opts = config.public.nuxtAuthKit;
8
- const tokenCookieName = opts?.tokenCookieName || "auth_token";
9
- const tokenCookie = useCookie(tokenCookieName);
10
- if (tokenCookie.value && !store.token) {
11
- store.setToken(tokenCookie.value);
12
- try {
13
- const { fetchUser } = useAuth();
14
- await fetchUser();
15
- } catch (_) {
16
- store.clearAuth();
17
- tokenCookie.value = null;
4
+ export default defineNuxtPlugin({
5
+ name: "nuxt-auth-kit",
6
+ // Run AFTER Pinia plugin so $pinia is available
7
+ dependsOn: ["pinia"],
8
+ async setup(nuxtApp) {
9
+ const store = useAuthStore(nuxtApp.$pinia);
10
+ const config = useRuntimeConfig();
11
+ const opts = config.public.nuxtAuthKit;
12
+ const tokenCookieName = opts?.tokenCookieName || "auth_token";
13
+ const tokenCookie = useCookie(tokenCookieName);
14
+ if (tokenCookie.value && !store.token) {
15
+ store.setToken(tokenCookie.value);
16
+ try {
17
+ const { fetchUser } = useAuth();
18
+ await fetchUser();
19
+ } catch (_) {
20
+ store.clearAuth();
21
+ tokenCookie.value = null;
22
+ }
18
23
  }
19
24
  }
20
25
  });
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "nuxt-auth-kit",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Nuxt module for authentication with Laravel API — login, register, profile, password management, roles & permissions",
5
5
  "keywords": ["nuxt", "nuxt-module", "authentication", "laravel", "roles", "permissions"],
6
+ "author": {
7
+ "name": "3S Tech Group",
8
+ "url": "https://github.com/sssadgroup/"
9
+ },
10
+ "homepage": "https://sssadgroup.github.io/nuxt-auth-kit",
6
11
  "license": "MIT",
7
12
  "type": "module",
8
13
  "exports": {