Invites
Queries and Mutations listed here are used to send requests to the Admin Invite API Routes.
All hooks listed require authentication.
An admin can invite new users to manage their team. This would allow new users to authenticate as admins and perform admin functionalities.
Related Guide: How to manage invites.
Mutations
useAdminAcceptInvite
This hook accepts an Invite. This will also delete the invite and create a new user that can log in and perform admin functionalities. The user will have the email associated with the invite, and the password provided in the mutation function's parameter.
Example
import React from "react"
import { useAdminAcceptInvite } from "medusa-react"
const AcceptInvite = () => {
const acceptInvite = useAdminAcceptInvite()
// ...
const handleAccept = (
token: string,
firstName: string,
lastName: string,
password: string
) => {
acceptInvite.mutate({
token,
user: {
first_name: firstName,
last_name: lastName,
password,
},
}, {
onSuccess: () => {
// invite accepted successfully.
}
})
}
// ...
}
export default AcceptInvite
Mutation Function Parameters
The details of the invite to be accepted.
useAdminResendInvite
This hook resends an invite. This renews the expiry date by seven days and generates a new token for the invite. It also triggers the invite.created
event,
so if you have a Notification Provider installed that handles this event, a notification should be sent to the email associated with the
invite to allow them to accept the invite.
Example
import React from "react"
import { useAdminResendInvite } from "medusa-react"
type Props = {
inviteId: string
}
const ResendInvite = ({ inviteId }: Props) => {
const resendInvite = useAdminResendInvite(inviteId)
// ...
const handleResend = () => {
resendInvite.mutate(void 0, {
onSuccess: () => {
// invite resent successfully
}
})
}
// ...
}
export default ResendInvite
Hook Parameters
id
stringRequireduseAdminDeleteInvite
This hook deletes an invite. Only invites that weren't accepted can be deleted.
Example
import React from "react"
import { useAdminDeleteInvite } from "medusa-react"
type Props = {
inviteId: string
}
const DeleteInvite = ({ inviteId }: Props) => {
const deleteInvite = useAdminDeleteInvite(inviteId)
// ...
const handleDelete = () => {
deleteInvite.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Invite
Hook Parameters
id
stringRequiredMutation Function Returned Data
The response returned for a
DELETE
request.
DELETE
request.Queries
useAdminInvites
This hook retrieves a list of invites.
Example
import React from "react"
import { useAdminInvites } from "medusa-react"
const Invites = () => {
const { invites, isLoading } = useAdminInvites()
return (
<div>
{isLoading && <span>Loading...</span>}
{invites && !invites.length && (
<span>No Invites</span>)
}
{invites && invites.length > 0 && (
<ul>
{invites.map((invite) => (
<li key={invite.id}>{invite.user_email}</li>
))}
</ul>
)}
</div>
)
}
export default Invites