feat: adding workflow to send invites to the user

This commit is contained in:
Pablo Lara
2024-11-13 17:18:32 +01:00
parent e4395ddd55
commit 29dfd303db
20 changed files with 664 additions and 18 deletions
+40
View File
@@ -0,0 +1,40 @@
"use server";
import { auth } from "@/auth.config";
import { getErrorMessage, parseStringify } from "@/lib";
export const sendInvite = async (formData: FormData) => {
const session = await auth();
const keyServer = process.env.API_BASE_URL;
const email = formData.get("email");
const url = new URL(`${keyServer}/tenants/invitations`);
const body = JSON.stringify({
data: {
type: "Invitation",
attributes: {
email,
},
relationships: {},
},
});
try {
const response = await fetch(url.toString(), {
method: "POST",
headers: {
"Content-Type": "application/vnd.api+json",
Accept: "application/vnd.api+json",
Authorization: `Bearer ${session?.accessToken}`,
},
body,
});
const data = await response.json();
return parseStringify(data);
} catch (error) {
return {
error: getErrorMessage(error),
};
}
};