Skip to content

Commit

Permalink
Add link in email for 2FA
Browse files Browse the repository at this point in the history
In addition to entering code, users can click the link to open jetstream and auto-enter the code

work towards #1076
  • Loading branch information
paustint committed Nov 17, 2024
1 parent a5ae6d9 commit ebed60a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
11 changes: 6 additions & 5 deletions libs/email/src/lib/components/EmailFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Section, Text } from '@react-email/components';
import { Link, Section, Text } from '@react-email/components';
import * as React from 'react';

export const EmailFooter = () => {
Expand Down Expand Up @@ -34,24 +34,25 @@ export const EmailFooter = () => {
fontSize: 12,
lineHeight: '18px',
fontWeight: 600,
color: 'rgb(107,114,128)',
color: '#6b7280',
textTransform: 'uppercase',
}}
>
Whitefish, MT USA
</Text>
<Text
<Link
href="mailto:[email protected]"
style={{
marginTop: 0,
marginBottom: '0px',
fontSize: 12,
lineHeight: '18px',
fontWeight: 600,
color: 'rgb(107,114,128)',
color: '#009aff',
}}
>
[email protected]
</Text>
</Link>
</td>
</tr>
</table>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { Body, Container, Head, Heading, Html, Preview, Section, Text } from '@react-email/components';
import { Body, Container, Head, Heading, Html, Link, Preview, Section, Text } from '@react-email/components';
import * as React from 'react';
import { EmailFooter } from '../../components/EmailFooter';
import { EmailLogo } from '../../components/EmailLogo';
import { EMAIL_STYLES } from '../../shared-styles';

interface TwoStepVerificationEmailProps {
baseUrl: string;
validationCode: string;
expMinutes: number;
}

export const TwoStepVerificationEmail = ({ validationCode, expMinutes }: TwoStepVerificationEmailProps) => (
export const TwoStepVerificationEmail = ({
baseUrl = 'https://getjetstream.app',
validationCode,
expMinutes,
}: TwoStepVerificationEmailProps) => (
<Html>
<Head />
<Preview>Verify your identity with Jetstream - {validationCode}</Preview>
Expand All @@ -26,6 +31,12 @@ export const TwoStepVerificationEmail = ({ validationCode, expMinutes }: TwoStep
<Heading style={EMAIL_STYLES.codeStyle}>{validationCode}</Heading>
</Section>

<Section style={EMAIL_STYLES.buttonContainer}>
<Link href={`${baseUrl}/auth/verify?type=2fa-email&code=${validationCode}`} style={EMAIL_STYLES.link}>
Or click this link
</Link>
</Section>

<Text style={EMAIL_STYLES.paragraphHeading}>Didn't request this?</Text>
<Text style={EMAIL_STYLES.paragraph}>If you didn't make this request, you can safely ignore this email.</Text>
</Container>
Expand Down
2 changes: 1 addition & 1 deletion libs/email/src/lib/email-templates/auth/VerifyEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EmailLogo } from '../../components/EmailLogo';
import { EMAIL_STYLES } from '../../shared-styles';

interface VerifyEmailProps {
baseUrl?: string;
baseUrl: string;
validationCode: string;
expHours: number;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/email/src/lib/email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function sendEmailVerification(emailAddress: string, code: string,
}

export async function sendVerificationCode(emailAddress: string, code: string, expMinutes: number) {
const component = <TwoStepVerificationEmail expMinutes={expMinutes} validationCode={code} />;
const component = <TwoStepVerificationEmail baseUrl={ENV.JETSTREAM_SERVER_URL} expMinutes={expMinutes} validationCode={code} />;
const [html, text] = await renderComponent(component);

await sendEmail({
Expand Down
2 changes: 1 addition & 1 deletion libs/email/src/lib/shared-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const paragraph: React.CSSProperties = {
};

const link: React.CSSProperties = {
color: '#444',
color: '#009aff',
textDecoration: 'underline',
};

Expand Down

0 comments on commit ebed60a

Please sign in to comment.