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
|
@@ -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
|
|
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(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
"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": {
|