feat(frontend): Add ogranization invitation
This commit is contained in:
@@ -40,10 +40,81 @@ export function useBetterAuth() {
|
||||
)
|
||||
}
|
||||
|
||||
async function getInvitation(invitationId: string): Promise<CustomInvitation> {
|
||||
return authClient.organization.getInvitation({
|
||||
query: { id: invitationId },
|
||||
fetchOptions: {
|
||||
throw: true,
|
||||
onSuccess: (ctx) => {
|
||||
return ctx.data
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.add({ title: 'Fehler beim Einladen', description: error.error.message, color: 'error' })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function inviteMember(email: string, role: 'member' | 'admin') {
|
||||
await authClient.organization.inviteMember({
|
||||
email,
|
||||
role,
|
||||
fetchOptions: {
|
||||
throw: true,
|
||||
onSuccess: (ctx) => {
|
||||
if (activeOrganization.value) {
|
||||
activeOrganization.value = {
|
||||
...activeOrganization.value,
|
||||
invitations: [...(activeOrganization.value?.invitations || []), ctx.data]
|
||||
}
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.add({ title: 'Fehler beim Einladen', description: error.error.message, color: 'error' })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function acceptInvitation(invitationId: string) {
|
||||
await authClient.organization.acceptInvitation({
|
||||
invitationId,
|
||||
fetchOptions: {
|
||||
throw: true,
|
||||
onSuccess: async () => {
|
||||
toast.add({ title: 'Invitation accepted', color: 'success' })
|
||||
await navigateTo('/')
|
||||
},
|
||||
onError: (ctx) => {
|
||||
toast.add({ title: 'Error when accepting invitation', description: ctx.error.message, color: 'error' })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function rejectInvitation(invitationId: string) {
|
||||
await authClient.organization.rejectInvitation({
|
||||
invitationId,
|
||||
fetchOptions: {
|
||||
throw: true,
|
||||
onSuccess: () => {
|
||||
toast.add({ title: 'Invitation rejected', color: 'success' })
|
||||
},
|
||||
onError: (ctx) => {
|
||||
toast.add({ title: 'Error when rejecting invitation', description: ctx.error.message, color: 'error' })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
activeOrganization,
|
||||
selectedOrgId,
|
||||
createOrganization,
|
||||
deleteOrganization
|
||||
deleteOrganization,
|
||||
getInvitation,
|
||||
inviteMember,
|
||||
acceptInvitation,
|
||||
rejectInvitation
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user