Skip to content

Commit

Permalink
Use different templates for sign ups and sign ins
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarvarela committed Dec 12, 2024
1 parent 1a9618a commit 18b9f24
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 243 deletions.
24 changes: 23 additions & 1 deletion site/gatsby-site/nextauth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,29 @@ export const getAuthConfig = async (req: any): Promise<NextAuthOptions> => {
name: "Email",
type: "email",
maxAge: 60 * 60 * 24, // Email link will expire in 24 hours
sendVerificationRequest,
async sendVerificationRequest({ identifier: email, url }: { identifier: string, url: string }) {

const user = await client.db('auth').collection('users').findOne({ email });

if (user) {

await sendEmail({
recipients: [{ email }],
subject: 'Login link',
templateId: 'Login',
dynamicData: { magicLink: url },
})
}
else {

await sendEmail({
recipients: [{ email }],
subject: 'Signup link',
templateId: 'Signup',
dynamicData: { magicLink: url },
})
}
}
}
],
theme: {
Expand Down
32 changes: 32 additions & 0 deletions site/gatsby-site/server/emails/templates/Login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
insertContent,
} from './shared'

const getEmailTemplate = () => {

return insertContent(
`
<div>
<p>
Click the link below to sign in to the AI Incident Database:
</p>
<p style="font-size: 85%;">
{{magicLink}}
</p>
<p>
This link will expire in 24 hours. If you did not request this email, please ignore it.
</p>
</div>
<p style="margin-bottom: 32px">
Sincerely,<br>
Responsible AI Collaborative
</p>
`,
{ title: 'Signup' }
);
};

export default getEmailTemplate();
234 changes: 0 additions & 234 deletions site/gatsby-site/server/emails/templates/MagicLink.ts

This file was deleted.

32 changes: 32 additions & 0 deletions site/gatsby-site/server/emails/templates/Signup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
insertContent,
} from './shared'

const getEmailTemplate = () => {

return insertContent(
`
<div>
<p>
Click the link below to verify your email address for the AI Incident Database:
</p>
<p style="font-size: 85%;">
{{magicLink}}
</p>
<p>
This link will expire in 24 hours. If you did not request this email, please ignore it.
</p>
</div>
<p style="margin-bottom: 32px">
Sincerely,<br>
Responsible AI Collaborative
</p>
`,
{ title: 'Signup' }
);
};

export default getEmailTemplate();
18 changes: 10 additions & 8 deletions site/gatsby-site/server/emails/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import EntityIncidentUpdated from './EntityIncidentUpdated';
import IncidentUpdate from './IncidentUpdate';
import MagicLink from './MagicLink';
import Login from './Login';
import Signup from './Signup';
import NewEntityIncident from './NewEntityIncident';
import NewIncident from './NewIncident';
import NewReportAddedToAnIncident from './NewReportAddedToAnIncident';
import SubmissionApproved from './SubmissionApproved';

const templates: Record<string, string> = {
EntityIncidentUpdated: EntityIncidentUpdated,
IncidentUpdate: IncidentUpdate,
NewEntityIncident: NewEntityIncident,
NewIncident: NewIncident,
NewReportAddedToAnIncident: NewReportAddedToAnIncident,
SubmissionApproved: SubmissionApproved,
MagicLink: MagicLink,
EntityIncidentUpdated,
IncidentUpdate,
NewEntityIncident,
NewIncident,
NewReportAddedToAnIncident,
SubmissionApproved,
Login,
Signup,
};

export default templates;

0 comments on commit 18b9f24

Please sign in to comment.