Files
baserow/e2e-tests/fixtures/workspaceMember.ts
alamin-br b14271c6e6 fix: accept workspace invitations only with the emailed token or a verified email (#6502)
* fix: accept workspace invitations only with the emailed token or a verified email

Accepting by id only compared the username with the invited address, which anyone can
register without verifying it. The emailed token now proves ownership and verifies the
email; without it, the user's email has to be verified.

* fix: require a verified email to reject invitations and keep accept visible

Rejecting still only checked the username, so whoever registered the invited address could delete the invitation. Accept stays visible after a verification error so it works once the email is verified.

* fix: hide accept for unverified users, allow reject, skip the check without SMTP

Without an email backend neither the invitation nor a verification email arrives, so the check can't be met.
Signing up from the invitation link verifies the email, so the user is signed in even when verification is enforced.

* fix: leaving a workspace hangs and removing the current user deletes the wrong workspace
2026-10-28 11:19:47 +01:00

24 lines
642 B
TypeScript

import { getClient } from "../client";
import { waitForInvitationToken } from "./mail";
import { User } from "./user";
import { Workspace } from "./workspace";
export async function addWorkspaceMember(
owner: User,
workspace: Workspace,
member: User,
permissions: string,
): Promise<void> {
const inviteResponse: any = await getClient(owner).post(
`workspaces/invitations/workspace/${workspace.id}/`,
{
email: member.email,
permissions,
},
);
await getClient(member).post(
`workspaces/invitations/${inviteResponse.data.id}/accept/`,
{ token: await waitForInvitationToken(member.email) },
);
}