Expired links (#94)
1. Handle expired links on signup 2.Reject invitations when user is already a member 3. Make sure not to display errors due to Next.js redirection during team creation 4. Fix documentation sidebar
This commit is contained in:
committed by
GitHub
parent
ae9c33aea4
commit
97d2cf9f85
@@ -101,6 +101,30 @@ class AccountInvitationsService {
|
||||
return data;
|
||||
}
|
||||
|
||||
async validateInvitation(
|
||||
invitation: z.infer<typeof InviteMembersSchema>['invitations'][number],
|
||||
accountSlug: string,
|
||||
) {
|
||||
const { data: members, error } = await this.client.rpc(
|
||||
'get_account_members',
|
||||
{
|
||||
account_slug: accountSlug,
|
||||
},
|
||||
);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const isUserAlreadyMember = members.find((member) => {
|
||||
return member.email === invitation.email;
|
||||
});
|
||||
|
||||
if (isUserAlreadyMember) {
|
||||
throw new Error('User already member of the team');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name sendInvitations
|
||||
* @description Sends invitations to join a team.
|
||||
@@ -123,6 +147,24 @@ class AccountInvitationsService {
|
||||
|
||||
logger.info(ctx, 'Storing invitations...');
|
||||
|
||||
try {
|
||||
await Promise.all(
|
||||
invitations.map((invitation) =>
|
||||
this.validateInvitation(invitation, accountSlug),
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
{
|
||||
...ctx,
|
||||
error: (error as Error).message,
|
||||
},
|
||||
'Error validating invitations',
|
||||
);
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
const accountResponse = await this.client
|
||||
.from('accounts')
|
||||
.select('name')
|
||||
|
||||
Reference in New Issue
Block a user