nuxt-auth-kit 1.0.1 → 1.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.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "nuxt-auth-kit",
3
3
  "configKey": "nuxtAuthKit",
4
4
  "compatibility": {
5
- "nuxt": "^3.0.0"
5
+ "nuxt": "^3.0.0 || ^4.0.0"
6
6
  },
7
- "version": "1.0.1",
7
+ "version": "1.0.3",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -1,11 +1,12 @@
1
- import { defineNuxtModule, createResolver, addPlugin, addImports, addRouteMiddleware, addComponent } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addPlugin, addImports, addComponent } from '@nuxt/kit';
2
+ import { join } from 'pathe';
2
3
 
3
4
  const module = defineNuxtModule({
4
5
  meta: {
5
6
  name: "nuxt-auth-kit",
6
7
  configKey: "nuxtAuthKit",
7
8
  compatibility: {
8
- nuxt: "^3.0.0"
9
+ nuxt: "^3.0.0 || ^4.0.0"
9
10
  }
10
11
  },
11
12
  defaults: {
@@ -57,31 +58,55 @@ const module = defineNuxtModule({
57
58
  from: resolver.resolve("./runtime/stores/auth")
58
59
  }
59
60
  ]);
60
- addRouteMiddleware({
61
- name: "auth",
62
- path: resolver.resolve("./runtime/middleware/auth"),
63
- global: false
64
- });
65
- addRouteMiddleware({
66
- name: "guest",
67
- path: resolver.resolve("./runtime/middleware/guest"),
68
- global: false
69
- });
70
- addRouteMiddleware({
71
- name: "role",
72
- path: resolver.resolve("./runtime/middleware/role"),
73
- global: false
61
+ nuxt.hook("app:resolve", (app) => {
62
+ const middlewareDir = resolver.resolve("./runtime/middleware");
63
+ for (const name of ["auth", "guest", "role"]) {
64
+ const path = join(middlewareDir, name);
65
+ const exists = app.middleware.find((m) => m.name === name);
66
+ if (!exists) {
67
+ app.middleware.push({ name, path, global: false });
68
+ }
69
+ }
74
70
  });
75
71
  const components = [
76
- // Auth
77
- { name: "AuthLayout", filePath: resolver.resolve("./runtime/components/auth/AuthLayout.vue") },
78
- { name: "AuthLoginForm", filePath: resolver.resolve("./runtime/components/auth/LoginForm.vue") },
79
- { name: "AuthRegisterForm", filePath: resolver.resolve("./runtime/components/auth/RegisterForm.vue") },
80
- { name: "AuthForgotPasswordForm", filePath: resolver.resolve("./runtime/components/auth/ForgotPasswordForm.vue") },
81
- { name: "AuthResetPasswordForm", filePath: resolver.resolve("./runtime/components/auth/ResetPasswordForm.vue") },
82
- // Profile
83
- { name: "ProfileUpdateForm", filePath: resolver.resolve("./runtime/components/profile/UpdateProfileForm.vue") },
84
- { name: "ProfileUpdatePasswordForm", filePath: resolver.resolve("./runtime/components/profile/UpdatePasswordForm.vue") }
72
+ {
73
+ name: "AuthLayout",
74
+ filePath: resolver.resolve("./runtime/components/auth/AuthLayout.vue")
75
+ },
76
+ {
77
+ name: "AuthLoginForm",
78
+ filePath: resolver.resolve("./runtime/components/auth/LoginForm.vue")
79
+ },
80
+ {
81
+ name: "AuthRegisterForm",
82
+ filePath: resolver.resolve(
83
+ "./runtime/components/auth/RegisterForm.vue"
84
+ )
85
+ },
86
+ {
87
+ name: "AuthForgotPasswordForm",
88
+ filePath: resolver.resolve(
89
+ "./runtime/components/auth/ForgotPasswordForm.vue"
90
+ )
91
+ },
92
+ {
93
+ name: "AuthResetPasswordForm",
94
+ filePath: resolver.resolve(
95
+ "./runtime/components/auth/ResetPasswordForm.vue"
96
+ )
97
+ },
98
+ {
99
+ name: "ProfileUpdateForm",
100
+ filePath: resolver.resolve(
101
+ "./runtime/components/profile/UpdateProfileForm.vue"
102
+ )
103
+ },
104
+ {
105
+ name: "ProfileUpdatePasswordForm",
106
+ filePath: resolver.resolve(
107
+ "./runtime/components/profile/UpdatePasswordForm.vue"
108
+ )
109
+ }
85
110
  ];
86
111
  for (const component of components) {
87
112
  addComponent(component);
@@ -1,4 +1,4 @@
1
- import type { LoginCredentials, RegisterData, UpdateProfileData, UpdatePasswordData, ForgotPasswordData, ResetPasswordData, ApiError } from '../types/index.js';
1
+ import type { LoginCredentials, RegisterData, UpdateProfileData, UpdatePasswordData, ForgotPasswordData, ResetPasswordData, ApiError } from "../types/index.js";
2
2
  export declare function useAuth(): {
3
3
  user: any;
4
4
  token: any;
@@ -33,7 +33,7 @@ export function useAuth() {
33
33
  async function apiFetch(path, options = {}) {
34
34
  const headers = {
35
35
  "Content-Type": "application/json",
36
- "Accept": "application/json",
36
+ Accept: "application/json",
37
37
  ...options.headers || {}
38
38
  };
39
39
  if (store.token) {
@@ -165,10 +165,13 @@ export function useAuth() {
165
165
  async function forgotPassword(data) {
166
166
  store.setLoading(true);
167
167
  try {
168
- const response = await apiFetch(endpoints.forgotPassword, {
169
- method: "POST",
170
- body: JSON.stringify(data)
171
- });
168
+ const response = await apiFetch(
169
+ endpoints.forgotPassword,
170
+ {
171
+ method: "POST",
172
+ body: JSON.stringify(data)
173
+ }
174
+ );
172
175
  return { success: true, message: response.message };
173
176
  } catch (error) {
174
177
  return { success: false, error };
@@ -179,10 +182,13 @@ export function useAuth() {
179
182
  async function resetPassword(data) {
180
183
  store.setLoading(true);
181
184
  try {
182
- const response = await apiFetch(endpoints.resetPassword, {
183
- method: "POST",
184
- body: JSON.stringify(data)
185
- });
185
+ const response = await apiFetch(
186
+ endpoints.resetPassword,
187
+ {
188
+ method: "POST",
189
+ body: JSON.stringify(data)
190
+ }
191
+ );
186
192
  return { success: true, message: response.message };
187
193
  } catch (error) {
188
194
  return { success: false, error };
@@ -1,4 +1,4 @@
1
- import type { AuthUser } from '../types/index.js';
1
+ import type { AuthUser } from "../types/index.js";
2
2
  export declare const useAuthStore: import("pinia").StoreDefinition<"nuxt-auth-kit", Pick<{
3
3
  user: import("vue").Ref<any, any>;
4
4
  token: import("vue").Ref<string | null, string | null>;
@@ -1,47 +1,51 @@
1
1
  import { defineStore } from "pinia";
2
2
  import { ref, computed } from "vue";
3
- export const useAuthStore = defineStore("nuxt-auth-kit", () => {
4
- const user = ref(null);
5
- const token = ref(null);
6
- const loading = ref(false);
7
- const isAuthenticated = computed(() => !!token.value && !!user.value);
8
- const isGuest = computed(() => !isAuthenticated.value);
9
- function hasRole(role) {
10
- if (!user.value?.roles) return false;
11
- const roles = Array.isArray(role) ? role : [role];
12
- return roles.some((r) => user.value.roles.includes(r));
3
+ export const useAuthStore = defineStore(
4
+ "nuxt-auth-kit",
5
+ () => {
6
+ const user = ref(null);
7
+ const token = ref(null);
8
+ const loading = ref(false);
9
+ const isAuthenticated = computed(() => !!token.value && !!user.value);
10
+ const isGuest = computed(() => !isAuthenticated.value);
11
+ function hasRole(role) {
12
+ if (!user.value?.roles) return false;
13
+ const roles = Array.isArray(role) ? role : [role];
14
+ return roles.some((r) => user.value.roles.includes(r));
15
+ }
16
+ function hasPermission(permission) {
17
+ if (!user.value?.permissions) return false;
18
+ const perms = Array.isArray(permission) ? permission : [permission];
19
+ return perms.some((p) => user.value.permissions.includes(p));
20
+ }
21
+ function setUser(userData) {
22
+ user.value = userData;
23
+ }
24
+ function setToken(tokenValue) {
25
+ token.value = tokenValue;
26
+ }
27
+ function clearAuth() {
28
+ user.value = null;
29
+ token.value = null;
30
+ }
31
+ function setLoading(state) {
32
+ loading.value = state;
33
+ }
34
+ return {
35
+ user,
36
+ token,
37
+ loading,
38
+ isAuthenticated,
39
+ isGuest,
40
+ hasRole,
41
+ hasPermission,
42
+ setUser,
43
+ setToken,
44
+ clearAuth,
45
+ setLoading
46
+ };
47
+ },
48
+ {
49
+ persist: false
13
50
  }
14
- function hasPermission(permission) {
15
- if (!user.value?.permissions) return false;
16
- const perms = Array.isArray(permission) ? permission : [permission];
17
- return perms.some((p) => user.value.permissions.includes(p));
18
- }
19
- function setUser(userData) {
20
- user.value = userData;
21
- }
22
- function setToken(tokenValue) {
23
- token.value = tokenValue;
24
- }
25
- function clearAuth() {
26
- user.value = null;
27
- token.value = null;
28
- }
29
- function setLoading(state) {
30
- loading.value = state;
31
- }
32
- return {
33
- user,
34
- token,
35
- loading,
36
- isAuthenticated,
37
- isGuest,
38
- hasRole,
39
- hasPermission,
40
- setUser,
41
- setToken,
42
- clearAuth,
43
- setLoading
44
- };
45
- }, {
46
- persist: false
47
- });
51
+ );
@@ -68,7 +68,7 @@ export interface ModuleOptions {
68
68
  resetPassword?: string;
69
69
  };
70
70
  /** Token storage strategy */
71
- tokenStorage?: 'cookie' | 'localStorage';
71
+ tokenStorage?: "cookie" | "localStorage";
72
72
  /** Cookie name for token */
73
73
  tokenCookieName?: string;
74
74
  /** Redirect routes */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-auth-kit",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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
6
  "license": "MIT",
@@ -23,7 +23,7 @@
23
23
  "typecheck": "npx vue-tsc --noEmit"
24
24
  },
25
25
  "peerDependencies": {
26
- "nuxt": "^3.0.0 || ^4.0.0"
26
+ "nuxt": "^3.0.0 || ^4.0.0"
27
27
  },
28
28
  "peerDependenciesMeta": {
29
29
  "@nuxt/ui": { "optional": true }
@@ -39,4 +39,4 @@
39
39
  "@pinia/nuxt": "^0.7.0",
40
40
  "pinia": "^2.2.0"
41
41
  }
42
- }
42
+ }