Skip to content

Commit

Permalink
fix(email): remove one-time password from invite for existing users
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Nov 25, 2023
1 parent f9ac171 commit 374d2e6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
10 changes: 8 additions & 2 deletions mods/apiserver/src/notifications/createInviteBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import fs from "fs";
import path from "path";

const TEMPLATE_DIR = path.join(__dirname, "templates");

enum TemplateName {
INVITE = "inviteTemplate"
INVITE_NEW_USER = "inviteNewUserTemplate",
INVITE_EXISTING_USER = "inviteExistingUserTemplate"
}

const compileTemplate = (
Expand All @@ -36,5 +38,9 @@ const compileTemplate = (
};

export function createInviteBody(data: Record<string, string>) {
return compileTemplate(TemplateName.INVITE, data);
if (data.oneTimePassword) {
return compileTemplate(TemplateName.INVITE_NEW_USER, data);
} else {
return compileTemplate(TemplateName.INVITE_EXISTING_USER, data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
<title>Invite</title>
</head>
<body>
<p>Welcome to Goodtok</p>
<p>To accept the invitation, please click the following link:
<a href="{{inviteUrl}}">{{inviteUrl}}</a>
</p>
</body>
</html>
3 changes: 2 additions & 1 deletion mods/apiserver/src/workspaces/addWorkspaceMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ export async function addWorkspaceMember(
}
});

const oneTimePassword = customAlphabet("1234567890abcdef", 10)();
let oneTimePassword;

if (!user) {
oneTimePassword = customAlphabet("1234567890abcdef", 10)();
// Let's create a new user with a one time password
logger.verbose("user does not exists, creating a new one", {
email
Expand Down
4 changes: 2 additions & 2 deletions mods/frontoffice/src/containers/SettingsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function SettingsContainer() {
workspaces
.getMembersByWorkspaceId(workspaceId)
.then((response) => {
const newMembers = response.members.map((member) => ({
const members = response.members.map((member) => ({
id: member.id,
userId: member.userId,
name: member.name,
Expand All @@ -244,7 +244,7 @@ function SettingsContainer() {
createdAt: new Date(member.createdAt)
}));

setMembers((prevMembers) => [prevMembers[0], ...newMembers]);
setMembers(members);
})
.catch((err) => {
logger.error("error getting workspace members", err);
Expand Down

0 comments on commit 374d2e6

Please sign in to comment.