nuxt-users 1.26.0 → 1.28.0
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/CHANGELOG.md +37 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/NUsersList.vue +22 -31
- package/dist/runtime/components/NUsersList.vue.d.ts +0 -68
- package/dist/runtime/components/NUsersLogoutLink.vue +10 -3
- package/dist/runtime/components/NUsersProfileInfo.vue +6 -1
- package/dist/runtime/components/NUsersUserCard.vue +7 -2
- package/dist/runtime/composables/useUsers.d.ts +20 -0
- package/dist/runtime/composables/useUsers.js +55 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v1.28.0
|
|
5
|
+
|
|
6
|
+
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.27.0...v1.28.0)
|
|
7
|
+
|
|
8
|
+
### 🚀 Enhancements
|
|
9
|
+
|
|
10
|
+
- Expose useUsers composable ([485d81c](https://github.com/rrd108/nuxt-users/commit/485d81c))
|
|
11
|
+
|
|
12
|
+
### 🩹 Fixes
|
|
13
|
+
|
|
14
|
+
- Composables are initialized on mount ([b25eb95](https://github.com/rrd108/nuxt-users/commit/b25eb95))
|
|
15
|
+
|
|
16
|
+
### 🏡 Chore
|
|
17
|
+
|
|
18
|
+
- **release:** V1.27.0 ([195a5b7](https://github.com/rrd108/nuxt-users/commit/195a5b7))
|
|
19
|
+
|
|
20
|
+
### ❤️ Contributors
|
|
21
|
+
|
|
22
|
+
- Rrd108 ([@rrd108](https://github.com/rrd108))
|
|
23
|
+
|
|
24
|
+
## v1.27.0
|
|
25
|
+
|
|
26
|
+
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.26.0...v1.27.0)
|
|
27
|
+
|
|
28
|
+
### 🚀 Enhancements
|
|
29
|
+
|
|
30
|
+
- Emit error ([0818b80](https://github.com/rrd108/nuxt-users/commit/0818b80))
|
|
31
|
+
- Expose useUsers composable ([485d81c](https://github.com/rrd108/nuxt-users/commit/485d81c))
|
|
32
|
+
|
|
33
|
+
### 🏡 Chore
|
|
34
|
+
|
|
35
|
+
- **release:** V1.26.0 ([3f90a9c](https://github.com/rrd108/nuxt-users/commit/3f90a9c))
|
|
36
|
+
|
|
37
|
+
### ❤️ Contributors
|
|
38
|
+
|
|
39
|
+
- Rrd108 ([@rrd108](https://github.com/rrd108))
|
|
40
|
+
|
|
4
41
|
## v1.26.0
|
|
5
42
|
|
|
6
43
|
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.25.0...v1.26.0)
|
package/dist/module.json
CHANGED
|
@@ -1,43 +1,34 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { onMounted, computed } from "vue";
|
|
3
|
+
import { useUsers } from "../composables/useUsers";
|
|
4
4
|
import { defaultDisplayFields, defaultFieldLabels } from "nuxt-users/utils";
|
|
5
5
|
defineProps({
|
|
6
6
|
displayFields: { type: Array, required: false, default: () => defaultDisplayFields },
|
|
7
7
|
fieldLabels: { type: Object, required: false, default: () => defaultFieldLabels }
|
|
8
8
|
});
|
|
9
9
|
const emit = defineEmits(["editClick", "delete"]);
|
|
10
|
-
|
|
11
|
-
const users =
|
|
12
|
-
const pagination =
|
|
13
|
-
const loading =
|
|
14
|
-
const error =
|
|
15
|
-
const fetchUsers = async (page = 1, limit = 100) => {
|
|
16
|
-
loading.value = true;
|
|
17
|
-
error.value = null;
|
|
18
|
-
try {
|
|
19
|
-
const response = await $fetch(`${nuxtUsers.apiBasePath}?page=${page}&limit=${limit}`);
|
|
20
|
-
users.value = response.users;
|
|
21
|
-
pagination.value = response.pagination;
|
|
22
|
-
} catch (err) {
|
|
23
|
-
error.value = err instanceof Error ? err.message : "Failed to fetch users";
|
|
24
|
-
} finally {
|
|
25
|
-
loading.value = false;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const refresh = () => {
|
|
29
|
-
fetchUsers();
|
|
30
|
-
};
|
|
31
|
-
defineExpose({
|
|
32
|
-
refresh
|
|
33
|
-
});
|
|
10
|
+
let usersComposable = null;
|
|
11
|
+
const users = computed(() => usersComposable?.users.value ?? []);
|
|
12
|
+
const pagination = computed(() => usersComposable?.pagination.value ?? null);
|
|
13
|
+
const loading = computed(() => usersComposable?.loading.value ?? false);
|
|
14
|
+
const error = computed(() => usersComposable?.error.value ?? null);
|
|
34
15
|
onMounted(() => {
|
|
35
|
-
|
|
16
|
+
usersComposable = useUsers();
|
|
17
|
+
if (users.value.length === 0) {
|
|
18
|
+
usersComposable.fetchUsers();
|
|
19
|
+
}
|
|
36
20
|
});
|
|
37
21
|
const handleDelete = (user) => {
|
|
38
|
-
|
|
22
|
+
if (usersComposable) {
|
|
23
|
+
usersComposable.removeUser(user.id);
|
|
24
|
+
}
|
|
39
25
|
emit("delete", user);
|
|
40
26
|
};
|
|
27
|
+
const handleFetchUsers = (page, limit) => {
|
|
28
|
+
if (usersComposable) {
|
|
29
|
+
usersComposable.fetchUsers(page, limit);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
41
32
|
</script>
|
|
42
33
|
|
|
43
34
|
<template>
|
|
@@ -116,7 +107,7 @@ const handleDelete = (user) => {
|
|
|
116
107
|
<slot
|
|
117
108
|
name="pagination"
|
|
118
109
|
:pagination="pagination"
|
|
119
|
-
:fetch-users="
|
|
110
|
+
:fetch-users="handleFetchUsers"
|
|
120
111
|
:loading="loading"
|
|
121
112
|
>
|
|
122
113
|
<div v-if="pagination && pagination.totalPages > 1">
|
|
@@ -124,7 +115,7 @@ const handleDelete = (user) => {
|
|
|
124
115
|
<button
|
|
125
116
|
v-if="pagination.hasPrev"
|
|
126
117
|
:disabled="loading"
|
|
127
|
-
@click="
|
|
118
|
+
@click="handleFetchUsers(pagination.page - 1)"
|
|
128
119
|
>
|
|
129
120
|
Previous
|
|
130
121
|
</button>
|
|
@@ -132,7 +123,7 @@ const handleDelete = (user) => {
|
|
|
132
123
|
<button
|
|
133
124
|
v-if="pagination.hasNext"
|
|
134
125
|
:disabled="loading"
|
|
135
|
-
@click="
|
|
126
|
+
@click="handleFetchUsers(pagination.page + 1)"
|
|
136
127
|
>
|
|
137
128
|
Next
|
|
138
129
|
</button>
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
interface Props {
|
|
2
|
-
displayFields?: string[];
|
|
3
|
-
fieldLabels?: Record<string, string>;
|
|
4
|
-
}
|
|
5
|
-
declare var __VLS_1: {}, __VLS_3: {
|
|
6
|
-
loading: boolean;
|
|
7
|
-
}, __VLS_5: {
|
|
8
|
-
error: string | null;
|
|
9
|
-
}, __VLS_7: {}, __VLS_9: {}, __VLS_16: {
|
|
10
|
-
user: any;
|
|
11
|
-
index: number;
|
|
12
|
-
}, __VLS_27: {
|
|
13
|
-
pagination: {
|
|
14
|
-
page: number;
|
|
15
|
-
limit: number;
|
|
16
|
-
total: number;
|
|
17
|
-
totalPages: number;
|
|
18
|
-
hasNext: boolean;
|
|
19
|
-
hasPrev: boolean;
|
|
20
|
-
} | null;
|
|
21
|
-
}, __VLS_29: {
|
|
22
|
-
pagination: {
|
|
23
|
-
page: number;
|
|
24
|
-
limit: number;
|
|
25
|
-
total: number;
|
|
26
|
-
totalPages: number;
|
|
27
|
-
hasNext: boolean;
|
|
28
|
-
hasPrev: boolean;
|
|
29
|
-
} | null;
|
|
30
|
-
fetchUsers: (page?: number, limit?: number) => Promise<void>;
|
|
31
|
-
loading: boolean;
|
|
32
|
-
};
|
|
33
|
-
type __VLS_Slots = {} & {
|
|
34
|
-
title?: (props: typeof __VLS_1) => any;
|
|
35
|
-
} & {
|
|
36
|
-
loading?: (props: typeof __VLS_3) => any;
|
|
37
|
-
} & {
|
|
38
|
-
error?: (props: typeof __VLS_5) => any;
|
|
39
|
-
} & {
|
|
40
|
-
noUsers?: (props: typeof __VLS_7) => any;
|
|
41
|
-
} & {
|
|
42
|
-
usersList?: (props: typeof __VLS_9) => any;
|
|
43
|
-
} & {
|
|
44
|
-
user?: (props: typeof __VLS_16) => any;
|
|
45
|
-
} & {
|
|
46
|
-
paginationInfo?: (props: typeof __VLS_27) => any;
|
|
47
|
-
} & {
|
|
48
|
-
pagination?: (props: typeof __VLS_29) => any;
|
|
49
|
-
};
|
|
50
|
-
declare const __VLS_component: import("vue").DefineComponent<Props, {
|
|
51
|
-
refresh: () => void;
|
|
52
|
-
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
53
|
-
delete: (user: User) => void;
|
|
54
|
-
editClick: (user: User) => void;
|
|
55
|
-
}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
|
|
56
|
-
onDelete?: ((user: User) => any) | undefined;
|
|
57
|
-
onEditClick?: ((user: User) => any) | undefined;
|
|
58
|
-
}>, {
|
|
59
|
-
displayFields: string[];
|
|
60
|
-
fieldLabels: Record<string, string>;
|
|
61
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
62
|
-
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
63
|
-
export default _default;
|
|
64
|
-
type __VLS_WithSlots<T, S> = T & {
|
|
65
|
-
new (): {
|
|
66
|
-
$slots: S;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { ref } from "vue";
|
|
2
|
+
import { ref, onMounted } from "vue";
|
|
3
3
|
import { navigateTo } from "#app";
|
|
4
4
|
import { useAuthentication } from "../composables/useAuthentication";
|
|
5
5
|
const props = defineProps({
|
|
@@ -16,19 +16,26 @@ const props = defineProps({
|
|
|
16
16
|
containerStyle: { type: [String, Object], required: false }
|
|
17
17
|
});
|
|
18
18
|
const emit = defineEmits(["success", "click", "error"]);
|
|
19
|
-
|
|
19
|
+
let authComposable = null;
|
|
20
20
|
const isLoading = ref(false);
|
|
21
21
|
const error = ref("");
|
|
22
|
+
onMounted(() => {
|
|
23
|
+
authComposable = useAuthentication();
|
|
24
|
+
});
|
|
22
25
|
const handleLogout = async (event) => {
|
|
23
26
|
event.preventDefault();
|
|
24
27
|
if (!confirm(props.confirmMessage)) {
|
|
25
28
|
return;
|
|
26
29
|
}
|
|
30
|
+
if (!authComposable) {
|
|
31
|
+
error.value = "Authentication not initialized";
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
27
34
|
isLoading.value = true;
|
|
28
35
|
error.value = "";
|
|
29
36
|
try {
|
|
30
37
|
emit("click");
|
|
31
|
-
await logout();
|
|
38
|
+
await authComposable.logout();
|
|
32
39
|
emit("success");
|
|
33
40
|
if (props.redirectTo) {
|
|
34
41
|
await navigateTo(props.redirectTo);
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import { computed, onMounted } from "vue";
|
|
2
3
|
import { useAuthentication } from "../composables/useAuthentication";
|
|
3
|
-
|
|
4
|
+
let authComposable = null;
|
|
5
|
+
const user = computed(() => authComposable?.user.value ?? null);
|
|
6
|
+
onMounted(() => {
|
|
7
|
+
authComposable = useAuthentication();
|
|
8
|
+
});
|
|
4
9
|
</script>
|
|
5
10
|
|
|
6
11
|
<template>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { computed } from "vue";
|
|
2
|
+
import { computed, onMounted } from "vue";
|
|
3
3
|
import { useAuthentication } from "../composables/useAuthentication";
|
|
4
4
|
import { useRuntimeConfig } from "#imports";
|
|
5
5
|
import { defaultDisplayFields, defaultFieldLabels } from "nuxt-users/utils";
|
|
@@ -10,8 +10,12 @@ const props = defineProps({
|
|
|
10
10
|
fieldLabels: { type: Object, required: false, default: () => defaultFieldLabels }
|
|
11
11
|
});
|
|
12
12
|
const emit = defineEmits(["delete", "editClick"]);
|
|
13
|
-
const { user: currentUser } = useAuthentication();
|
|
14
13
|
const { public: { nuxtUsers } } = useRuntimeConfig();
|
|
14
|
+
let authComposable = null;
|
|
15
|
+
const currentUser = computed(() => authComposable?.user.value ?? null);
|
|
16
|
+
onMounted(() => {
|
|
17
|
+
authComposable = useAuthentication();
|
|
18
|
+
});
|
|
15
19
|
const canEdit = computed(() => {
|
|
16
20
|
if (!currentUser.value) return false;
|
|
17
21
|
if (nuxtUsers.auth?.permissions) {
|
|
@@ -35,6 +39,7 @@ const canDelete = computed(() => {
|
|
|
35
39
|
return false;
|
|
36
40
|
});
|
|
37
41
|
const editUser = async (user) => {
|
|
42
|
+
console.info("The edit event is emitted. Nuxt-users does not automatically calls the API to update the user, you should do it at the upper component.");
|
|
38
43
|
emit("editClick", user);
|
|
39
44
|
};
|
|
40
45
|
const deleteUser = async (user) => {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { User } from '../../types.js';
|
|
2
|
+
interface Pagination {
|
|
3
|
+
page: number;
|
|
4
|
+
limit: number;
|
|
5
|
+
total: number;
|
|
6
|
+
totalPages: number;
|
|
7
|
+
hasNext: boolean;
|
|
8
|
+
hasPrev: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const useUsers: () => {
|
|
11
|
+
users: import("vue").Ref<User[], User[]>;
|
|
12
|
+
pagination: import("vue").Ref<Pagination | null, Pagination | null>;
|
|
13
|
+
loading: import("vue").Ref<boolean, boolean>;
|
|
14
|
+
error: import("vue").Ref<string | null, string | null>;
|
|
15
|
+
fetchUsers: (page?: number, limit?: number) => Promise<void>;
|
|
16
|
+
updateUser: (updatedUser: User) => void;
|
|
17
|
+
addUser: (newUser: User) => void;
|
|
18
|
+
removeUser: (userId: number) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useState, useRuntimeConfig } from "#imports";
|
|
2
|
+
const usersState = useState("users", () => []);
|
|
3
|
+
const paginationState = useState("users-pagination", () => null);
|
|
4
|
+
export const useUsers = () => {
|
|
5
|
+
const { public: { nuxtUsers } } = useRuntimeConfig();
|
|
6
|
+
const loading = useState("users-loading", () => false);
|
|
7
|
+
const error = useState("users-error", () => null);
|
|
8
|
+
const fetchUsers = async (page = 1, limit = 100) => {
|
|
9
|
+
if (loading.value) return;
|
|
10
|
+
loading.value = true;
|
|
11
|
+
error.value = null;
|
|
12
|
+
try {
|
|
13
|
+
const response = await $fetch(`${nuxtUsers.apiBasePath}?page=${page}&limit=${limit}`);
|
|
14
|
+
usersState.value = response.users;
|
|
15
|
+
paginationState.value = response.pagination;
|
|
16
|
+
} catch (err) {
|
|
17
|
+
error.value = err instanceof Error ? err.message : "Failed to fetch users";
|
|
18
|
+
usersState.value = [];
|
|
19
|
+
paginationState.value = null;
|
|
20
|
+
} finally {
|
|
21
|
+
loading.value = false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const updateUser = (updatedUser) => {
|
|
25
|
+
const index = usersState.value.findIndex((u) => u.id === updatedUser.id);
|
|
26
|
+
if (index !== -1) {
|
|
27
|
+
usersState.value[index] = updatedUser;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const addUser = (newUser) => {
|
|
31
|
+
usersState.value.unshift(newUser);
|
|
32
|
+
};
|
|
33
|
+
const removeUser = async (userId) => {
|
|
34
|
+
loading.value = true;
|
|
35
|
+
error.value = null;
|
|
36
|
+
try {
|
|
37
|
+
await $fetch(`${nuxtUsers.apiBasePath}/${userId}`, { method: "DELETE" });
|
|
38
|
+
usersState.value = usersState.value.filter((u) => u.id !== userId);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
error.value = err instanceof Error ? err.message : "Failed to delete user";
|
|
41
|
+
} finally {
|
|
42
|
+
loading.value = false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
users: usersState,
|
|
47
|
+
pagination: paginationState,
|
|
48
|
+
loading,
|
|
49
|
+
error,
|
|
50
|
+
fetchUsers,
|
|
51
|
+
updateUser,
|
|
52
|
+
addUser,
|
|
53
|
+
removeUser
|
|
54
|
+
};
|
|
55
|
+
};
|
package/package.json
CHANGED