feat(email): send team invitations from a Vercel serverless route (Twilio)
- POST /api/email/invite: sends the invite email via the Twilio Emails API using server-only TWILIO_ACCOUNT_SID/TWILIO_AUTH_TOKEN (Vercel env), from EMAIL_FROM_ADDRESS (default support@lynkedup.dev). Fixed invite template; gated on a session cookie so it isn't an open relay. - Team Management emails the invite on create and resend (token now returned by both), with the Copy-link as a fallback. Mock mode skips email.
This commit is contained in:
+16
-5
@@ -48,8 +48,10 @@ export interface TeamData {
|
||||
setMemberRoles: (id: string, roleIds: string[]) => Promise<void>;
|
||||
updateMember: (id: string, patch: { title?: string; roleIds?: string[] }) => Promise<void>;
|
||||
removeMember: (id: string) => Promise<void>;
|
||||
invite: (email: string, roleIds: string[]) => Promise<void>;
|
||||
resendInvite: (id: string) => Promise<void>;
|
||||
/** Create an invite; resolves with the accept token so the caller can email the link. */
|
||||
invite: (email: string, roleIds: string[]) => Promise<{ token?: string }>;
|
||||
/** Resend an invite (regenerates the token); resolves with the fresh token. */
|
||||
resendInvite: (id: string) => Promise<{ token?: string }>;
|
||||
revokeInvite: (id: string) => Promise<void>;
|
||||
setPermission: (roleId: string, permId: string, granted: boolean) => Promise<void>;
|
||||
refetch: () => void;
|
||||
@@ -115,8 +117,9 @@ function useMockTeam(): TeamData {
|
||||
const removeMember = useCallback(async (id: string) => { setMembers((l) => l.filter((m) => m.id !== id)); }, []);
|
||||
const invite = useCallback(async (email: string, roleIds: string[]) => {
|
||||
setInvites((l) => [{ id: `inv_${Date.now()}`, email, roleIds, invitedBy: "James Carter", sentAt: "Just now" }, ...l]);
|
||||
return {};
|
||||
}, []);
|
||||
const resendInvite = useCallback(async () => {}, []);
|
||||
const resendInvite = useCallback(async () => ({}), []);
|
||||
const revokeInvite = useCallback(async (id: string) => { setInvites((l) => l.filter((i) => i.id !== id)); }, []);
|
||||
const setPermission = useCallback(async (roleId: string, permId: string, granted: boolean) => {
|
||||
setRoles((l) => l.map((r) => (r.id !== roleId ? r : {
|
||||
@@ -184,8 +187,16 @@ function useLiveTeam(): TeamData {
|
||||
id, ...(patch.title !== undefined ? { jobTitle: patch.title } : {}), ...(patch.roleIds ? { roleIds: patch.roleIds } : {}),
|
||||
}),
|
||||
removeMember: (id) => cmd("crm.team.member.remove", { id }),
|
||||
invite: (email, roleIds) => cmd("crm.team.invitation.create", { email, roleIds }),
|
||||
resendInvite: (id) => cmd("crm.team.invitation.resend", { id }),
|
||||
invite: async (email, roleIds) => {
|
||||
const dto = (await sdk.command("crm.team.invitation.create", { email, roleIds })) as { token?: string } | undefined;
|
||||
refetch();
|
||||
return { token: dto?.token };
|
||||
},
|
||||
resendInvite: async (id) => {
|
||||
const res = (await sdk.command("crm.team.invitation.resend", { id })) as { token?: string } | undefined;
|
||||
refetch();
|
||||
return { token: res?.token };
|
||||
},
|
||||
revokeInvite: (id) => cmd("crm.team.invitation.revoke", { id }),
|
||||
setPermission: (roleId, permId, granted) =>
|
||||
cmd(granted ? "crm.team.role.addPermission" : "crm.team.role.removePermission", { id: roleId, permissionId: permId }),
|
||||
|
||||
Reference in New Issue
Block a user