@nuxt-customer-portal/organizations 0.3.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -0
  4. package/app/components/DeleteAccountModal.vue +139 -0
  5. package/app/components/OrganizationMembers.vue +298 -0
  6. package/app/components/OrganizationSettings.vue +315 -0
  7. package/app/components/OrganizationSwitcher.vue +166 -0
  8. package/app/components/organization/DetailsCard.vue +84 -0
  9. package/app/components/organization/InvitationsCard.vue +112 -0
  10. package/app/components/organization/InviteMemberModal.vue +101 -0
  11. package/app/components/organization/MembersCard.vue +108 -0
  12. package/app/pages/my-organizations.vue +125 -0
  13. package/app/pages/settings/index.vue +248 -0
  14. package/app/pages/settings/organization.vue +171 -0
  15. package/app/pages/settings/security.vue +195 -0
  16. package/app/pages/settings.vue +101 -0
  17. package/app/plugins/account-organizations-feature.ts +3 -0
  18. package/i18n/locales/en.json +208 -0
  19. package/i18n/locales/nl.json +208 -0
  20. package/nuxt.config.ts +11 -0
  21. package/package.json +51 -0
  22. package/portal.manifest.mjs +6 -0
  23. package/server/api/organizations/[id]/index.get.ts +54 -0
  24. package/server/api/organizations/[id]/invitations/[invitationId]/delete.post.ts +42 -0
  25. package/server/api/organizations/[id]/invitations/[invitationId]/resend.post.ts +91 -0
  26. package/server/api/organizations/[id]/invitations/[invitationId].patch.ts +18 -0
  27. package/server/api/organizations/[id]/invitations.get.ts +49 -0
  28. package/server/api/organizations/accept-invitation.post.ts +131 -0
  29. package/server/api/organizations/get-invitation.get.ts +73 -0
  30. package/server/api/profile.patch.ts +99 -0
  31. package/shared/feature.ts +24 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # @nuxt-customer-portal/organizations
2
+
3
+ ## 0.3.0
4
+
5
+ Declare the Nuxt UI dependency used by the package's public components and types,
6
+ so npm installations do not depend on another package's dependency layout.
7
+
8
+ ### Patch Changes
9
+
10
+ - @nuxt-customer-portal/core@0.3.0
11
+ - @nuxt-customer-portal/ui@0.3.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nuxt Customer Portal contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Account and organizations layer
2
+
3
+ Owns profile, security, organization membership, invitations, and organization settings.
@@ -0,0 +1,139 @@
1
+ <script setup lang="ts">
2
+ import * as z from 'zod'
3
+ import type { FormSubmitEvent } from '@nuxt/ui'
4
+ import { authClient } from '@nuxt-customer-portal/core/app/utils/auth-client'
5
+
6
+ const props = defineProps<{
7
+ requiresPassword: boolean
8
+ }>()
9
+
10
+ const emit = defineEmits<{
11
+ success: []
12
+ error: [message: string]
13
+ }>()
14
+
15
+ const open = defineModel<boolean>('open', { default: false })
16
+ const { t } = useI18n()
17
+ const toast = useToast()
18
+
19
+ const isLoading = ref(false)
20
+
21
+ const passwordSchema = computed(() => {
22
+ if (!props.requiresPassword) {
23
+ return z.object({})
24
+ }
25
+ return z.object({
26
+ password: z.string().min(1, t('security.account.delete.passwordRequired'))
27
+ })
28
+ })
29
+
30
+ type PasswordSchema = z.output<typeof passwordSchema.value>
31
+
32
+ const passwordForm = reactive({
33
+ password: '' as string | undefined
34
+ })
35
+
36
+ const handleDelete = async (event?: FormSubmitEvent<PasswordSchema>) => {
37
+ isLoading.value = true
38
+
39
+ try {
40
+ type DeleteParams = { password?: string; callbackURL?: string }
41
+ const deleteParams: DeleteParams = {
42
+ callbackURL: '/'
43
+ }
44
+
45
+ const hasPassword = props.requiresPassword && event?.data?.password
46
+ if (hasPassword && event.data.password && typeof event.data.password === 'string') {
47
+ deleteParams.password = event.data.password
48
+ }
49
+
50
+ const { error } = await authClient.deleteUser(deleteParams)
51
+
52
+ if (error) {
53
+ throw error
54
+ }
55
+
56
+ // No password - email verification was sent
57
+ toast.add({
58
+ title: t('common.success'),
59
+ description: t('security.account.delete.emailVerificationSent'),
60
+ color: 'success'
61
+ })
62
+
63
+ // Don't logout - user needs to click email link
64
+ emit('success')
65
+ open.value = false
66
+ passwordForm.password = undefined
67
+ } catch (err: unknown) {
68
+ let errorMessage = t('security.account.delete.error')
69
+
70
+ if (err instanceof Error) {
71
+ errorMessage = err.message
72
+ } else if (err && typeof err === 'object' && 'message' in err) {
73
+ errorMessage = String(err.message)
74
+ }
75
+
76
+ toast.add({
77
+ title: t('common.error'),
78
+ description: errorMessage,
79
+ color: 'error'
80
+ })
81
+ emit('error', errorMessage)
82
+ } finally {
83
+ isLoading.value = false
84
+ }
85
+ }
86
+
87
+ const handleCancel = () => {
88
+ open.value = false
89
+ passwordForm.password = undefined
90
+ }
91
+ </script>
92
+
93
+ <template>
94
+ <UModal v-model:open="open" :title="t('security.account.delete.confirmTitle')" :ui="{ footer: 'justify-end' }">
95
+ <template #body>
96
+ <div class="space-y-4">
97
+ <p class="text-sm text-gray-600 dark:text-gray-400">
98
+ {{ t('security.account.delete.confirmMessage') }}
99
+ </p>
100
+
101
+ <UForm
102
+ v-if="requiresPassword"
103
+ :schema="passwordSchema"
104
+ :state="passwordForm as unknown as PasswordSchema"
105
+ class="space-y-4"
106
+ @submit="handleDelete"
107
+ >
108
+ <UFormField name="password" :label="t('security.account.delete.passwordRequired')">
109
+ <UInput
110
+ v-model="passwordForm.password"
111
+ type="password"
112
+ :placeholder="t('security.account.delete.passwordPlaceholder')"
113
+ class="w-full"
114
+ :disabled="isLoading"
115
+ />
116
+ </UFormField>
117
+
118
+ <div class="flex gap-4 justify-end pt-4">
119
+ <UButton type="button" variant="outline" :disabled="isLoading" @click="handleCancel">
120
+ {{ t('security.account.delete.cancelButton') }}
121
+ </UButton>
122
+ <UButton type="submit" color="error" :loading="isLoading" :disabled="isLoading">
123
+ {{ t('security.account.delete.deleteButton') }}
124
+ </UButton>
125
+ </div>
126
+ </UForm>
127
+
128
+ <div v-else class="flex gap-4 justify-end pt-4">
129
+ <UButton type="button" variant="outline" :disabled="isLoading" @click="handleCancel">
130
+ {{ t('security.account.delete.cancelButton') }}
131
+ </UButton>
132
+ <UButton type="button" color="error" :loading="isLoading" :disabled="isLoading" @click="handleDelete()">
133
+ {{ t('security.account.delete.deleteButton') }}
134
+ </UButton>
135
+ </div>
136
+ </div>
137
+ </template>
138
+ </UModal>
139
+ </template>
@@ -0,0 +1,298 @@
1
+ <template>
2
+ <div>
3
+ <h1>Organization Members</h1>
4
+ </div>
5
+ </template>
6
+ <!-- <script setup lang="ts">
7
+ import { authClient } from '@nuxt-customer-portal/core/app/utils/auth-client'
8
+ import type { OrganizationMemberWithUser, OrganizationInvitationsResponse, MemberRole, ApiError } from '@nuxt-customer-portal/core/shared/types/index'
9
+
10
+ const showInviteModal = defineModel<boolean>('showInviteModal', { required: false })
11
+ const members = ref<OrganizationMemberWithUser[]>([])
12
+ const invitations = ref<OrganizationInvitationsResponse>([])
13
+ const loading = ref(true)
14
+ const error = ref('')
15
+ const inviteEmail = ref('')
16
+ const inviteRole = ref<MemberRole>('member')
17
+ const inviting = ref(false)
18
+
19
+ const loadMembers = async () => {
20
+ if (!organizationId.value) return
21
+
22
+ try {
23
+ loading.value = true
24
+ const { data, error: membersError } = await authClient.organization.listMembers({
25
+ query: { organizationId: organizationId.value }
26
+ })
27
+ if (membersError) throw membersError
28
+ // Handle both array response and object response with members property
29
+ if (Array.isArray(data)) {
30
+ members.value = data as OrganizationMemberWithUser[]
31
+ } else if (data?.members) {
32
+ members.value = data.members as OrganizationMemberWithUser[]
33
+ } else {
34
+ members.value = []
35
+ }
36
+ } catch (err) {
37
+ const apiError = err as ApiError
38
+ error.value = apiError.message || 'Failed to load members'
39
+ } finally {
40
+ loading.value = false
41
+ }
42
+ }
43
+
44
+ const loadInvitations = async () => {
45
+ if (!organizationId.value) return
46
+
47
+ try {
48
+ // Better-auth doesn't have a direct list invitations endpoint,
49
+ // so we'll need to create a custom API endpoint or fetch from the database
50
+ // For now, we'll fetch from a custom endpoint
51
+ const data = await $fetch<OrganizationInvitationsResponse>(`/api/organizations/${organizationId.value}/invitations`)
52
+ invitations.value = data || []
53
+ } catch (err) {
54
+ const apiError = err as ApiError
55
+ console.error('Failed to load invitations:', apiError)
56
+ invitations.value = []
57
+ }
58
+ }
59
+
60
+ const inviteMember = async () => {
61
+ if (!organizationId.value) return
62
+
63
+ try {
64
+ inviting.value = true
65
+ await authClient.organization.inviteMember({
66
+ email: inviteEmail.value,
67
+ organizationId: organizationId.value,
68
+ role: inviteRole.value
69
+ })
70
+ showInviteModal.value = false
71
+ inviteEmail.value = ''
72
+ inviteRole.value = 'member'
73
+ await loadInvitations()
74
+ // Show success message - you might want to add a toast notification here
75
+ } catch (err) {
76
+ const apiError = err as ApiError
77
+ error.value = apiError.message || 'Failed to send invitation'
78
+ } finally {
79
+ inviting.value = false
80
+ }
81
+ }
82
+
83
+ const updateMemberRole = async (member: OrganizationMemberWithUser, newRole: MemberRole) => {
84
+ try {
85
+ await authClient.organization.updateMemberRole({
86
+ memberId: member.id,
87
+ organizationId: organizationId.value!,
88
+ role: newRole
89
+ })
90
+ await loadMembers()
91
+ } catch (err) {
92
+ const apiError = err as ApiError
93
+ error.value = apiError.message || 'Failed to update member role'
94
+ }
95
+ }
96
+
97
+ const removeMember = async (member: OrganizationMemberWithUser) => {
98
+ if (!confirm(`Remove ${member.user.email} from organization?`)) return
99
+
100
+ try {
101
+ await authClient.organization.removeMember({
102
+ memberIdOrEmail: member.user.email,
103
+ organizationId: organizationId.value!
104
+ })
105
+ await loadMembers()
106
+ } catch (err) {
107
+ const apiError = err as ApiError
108
+ error.value = apiError.message || 'Failed to remove member'
109
+ }
110
+ }
111
+
112
+ onMounted(() => {
113
+ loadMembers()
114
+ loadInvitations()
115
+ })
116
+ </script>
117
+
118
+ <template>
119
+ <div class="organization-members">
120
+ <div class="members-header">
121
+ <h3>Organization Members</h3>
122
+ <button class="btn-primary" @click="showInviteModal = true">
123
+ Invite Member
124
+ </button>
125
+ </div>
126
+
127
+ <div v-if="loading" class="loading">Loading members...</div>
128
+ <div v-else-if="error" class="error">{{ error }}</div>
129
+ <div v-else class="members-list">
130
+ <div v-for="member in members" :key="member.id" class="member-card">
131
+ <div class="member-info">
132
+ <div class="member-name">{{ member.user.name || member.user.email }}</div>
133
+ <div class="member-email">{{ member.user.email }}</div>
134
+ <div class="member-role">
135
+ <UBadge
136
+ :color="member.role === 'owner' ? 'primary' : member.role === 'admin' ? 'info' : 'neutral'"
137
+ variant="soft"
138
+ >
139
+ {{ Array.isArray(member.role) ? member.role.join(', ') : member.role }}
140
+ </UBadge>
141
+ </div>
142
+ </div>
143
+ <div class="member-actions">
144
+ <UDropdownMenu :items="[
145
+ {
146
+ label: 'Member',
147
+ onClick: () => updateMemberRole(member, 'member')
148
+ },
149
+ {
150
+ label: 'Admin',
151
+ onClick: () => updateMemberRole(member, 'admin')
152
+ },
153
+ {
154
+ label: 'Owner',
155
+ onClick: () => updateMemberRole(member, 'owner')
156
+ }
157
+ ]">
158
+ <UButton variant="outline" size="sm">
159
+ Change Role
160
+ </UButton>
161
+ </UDropdownMenu>
162
+ <UButton
163
+ color="error"
164
+ variant="outline"
165
+ size="sm"
166
+ @click="removeMember(member)"
167
+ >
168
+ Remove
169
+ </UButton>
170
+ </div>
171
+ </div>
172
+ </div>
173
+
174
+ <div v-if="invitations.length > 0" class="mt-6">
175
+ <h4 class="text-lg font-semibold mb-4">Pending Invitations</h4>
176
+ <div class="space-y-2">
177
+ <div
178
+ v-for="invitation in invitations"
179
+ :key="invitation.id"
180
+ class="member-card"
181
+ >
182
+ <div class="member-info">
183
+ <div class="member-email">{{ invitation.email }}</div>
184
+ <div class="member-role">{{ invitation.role || 'member' }}</div>
185
+ <div class="text-xs text-gray-500">
186
+ Expires: {{ new Date(invitation.expiresAt).toLocaleDateString() }}
187
+ </div>
188
+ </div>
189
+ <div class="member-actions">
190
+ <UBadge color="warning" variant="soft">Pending</UBadge>
191
+ </div>
192
+ </div>
193
+ </div>
194
+ </div>
195
+
196
+ <UModal v-model="showInviteModal" @close="showInviteModal = false">
197
+ <UCard>
198
+ <template #header>
199
+ <h3 class="text-lg font-semibold">Invite Member</h3>
200
+ </template>
201
+
202
+ <form class="space-y-4" @submit.prevent="inviteMember">
203
+ <UFormGroup label="Email" required>
204
+ <UInput
205
+ id="invite-email"
206
+ v-model="inviteEmail"
207
+ type="email"
208
+ placeholder="user@example.com"
209
+ required
210
+ />
211
+ </UFormGroup>
212
+
213
+ <UFormGroup label="Role">
214
+ <USelect
215
+ v-model="inviteRole"
216
+ :options="[
217
+ { label: 'Member', value: 'member' },
218
+ { label: 'Admin', value: 'admin' },
219
+ { label: 'Owner', value: 'owner' }
220
+ ]"
221
+ option-attribute="label"
222
+ value-attribute="value"
223
+ />
224
+ </UFormGroup>
225
+
226
+ <UAlert
227
+ v-if="error"
228
+ color="error"
229
+ :title="error" variant="outline" />
230
+
231
+ <div class="flex gap-4 justify-end">
232
+ <UButton
233
+ type="button"
234
+ variant="outline"
235
+ @click="showInviteModal = false"
236
+ >
237
+ Cancel
238
+ </UButton>
239
+ <UButton
240
+ type="submit"
241
+ :disabled="inviting"
242
+ :loading="inviting"
243
+ >
244
+ {{ inviting ? 'Sending...' : 'Send Invitation' }}
245
+ </UButton>
246
+ </div>
247
+ </form>
248
+ </UCard>
249
+ </UModal>
250
+ </div>
251
+ </template>
252
+
253
+ <style scoped>
254
+ .organization-members {
255
+ padding: 1rem;
256
+ }
257
+
258
+ .members-header {
259
+ display: flex;
260
+ justify-content: space-between;
261
+ align-items: center;
262
+ margin-bottom: 1rem;
263
+ }
264
+
265
+ .member-card {
266
+ display: flex;
267
+ justify-content: space-between;
268
+ align-items: center;
269
+ padding: 1rem;
270
+ border: 1px solid #e5e7eb;
271
+ border-radius: 0.5rem;
272
+ margin-bottom: 0.5rem;
273
+ }
274
+
275
+ .member-info {
276
+ flex: 1;
277
+ }
278
+
279
+ .member-name {
280
+ font-weight: 500;
281
+ }
282
+
283
+ .member-email {
284
+ color: #6b7280;
285
+ font-size: 0.875rem;
286
+ }
287
+
288
+ .member-role {
289
+ color: #3b82f6;
290
+ font-size: 0.875rem;
291
+ }
292
+
293
+ .member-actions {
294
+ display: flex;
295
+ gap: 0.5rem;
296
+ align-items: center;
297
+ }
298
+ </style> -->