Skip to content

Commit

Permalink
Add passportURL to generateEmailOTP and EmailTemplateOTP
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmin-Parvulescu committed Oct 27, 2023
1 parent 603f25b commit a88737c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const action: ActionFunction = getRollupReqFunctionErrorWrapper(

try {
await coreClient.account.generateEmailOTP.mutate({
passportURL: context.env.PASSPORT_URL,
clientId,
email,
themeProps: {
Expand Down
2 changes: 2 additions & 0 deletions apps/passport/app/routes/connect/email/otp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export const loader: LoaderFunction = getRollupReqFunctionErrorWrapper(
}

const state = await coreClient.account.generateEmailOTP.mutate({
passportURL:
context.env.PASSPORT_REDIRECT_URL.split('/connect/token')[0],
clientId,
email,
themeProps,
Expand Down
4 changes: 3 additions & 1 deletion platform/account/src/jsonrpc/methods/generateEmailOTP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { EmailThemePropsSchema } from '../../../../email/src/emailFunctions'
export const GenerateEmailOTPInput = z.object({
email: z.string(),
clientId: z.string(),
passportURL: z.string().url(),
themeProps: EmailThemePropsSchema.optional(),
preview: z.boolean().optional(),
})
Expand All @@ -27,7 +28,7 @@ export const generateEmailOTPMethod = async ({
input: GenerateEmailOTPParams
ctx: Context
}): Promise<string> => {
const { email, themeProps, preview, clientId } = input
const { email, themeProps, preview, clientId, passportURL } = input
const emailAccountNode = new EmailAccount(ctx.account as AccountNode, ctx.env)

const state = generateRandomString(EMAIL_VERIFICATION_OPTIONS.STATE_LENGTH)
Expand All @@ -45,6 +46,7 @@ export const generateEmailOTPMethod = async ({
name: email,
otpCode: code,
themeProps,
passportURL,
})
return state
}
3 changes: 2 additions & 1 deletion platform/email/emailTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,14 @@ export const EmailTemplateOTP = (
clientId: string,
email: string,
state: string,
passportURL: string,
params: EmailTemplateParams
): EmailContent => {
const content = `
<div class="heading" style="font-size: 36px; font-weight: bold; line-height: 44px; margin-bottom: 16px;">Confirm Your Email Address</div>
<p style="font-size: 16px; font-weight: normal; line-height: 24px; margin-bottom: 16px;">Please copy the code below into the email verification screen.</p>
<div style="width: 100%; text-align: center; font-size: 46px; font-weight: bold; border-radius: 8px; margin-top: 20px; margin-bottom: 20px; padding: 15px 0; background-color: #f3f4f6;" id="passcode">${passcode}</div>
<div style="width: 100%; text-align: center; font-size: 46px; font-weight: bold; border-radius: 8px; margin-top: 20px; margin-bottom: 20px; padding: 15px 0; background-color: #f3f4f6;" id="magiclink">/magic?code=${passcode}&state=${state}&email=${email}&clientId=${clientId}</div>
<div style="width: 100%; text-align: center; font-size: 46px; font-weight: bold; border-radius: 8px; margin-top: 20px; margin-bottom: 20px; padding: 15px 0; background-color: #f3f4f6;" id="magiclink">${passportURL}/magic?code=${passcode}&state=${state}&email=${email}&clientId=${clientId}</div>
<p style="font-size: 16px; font-weight: normal; line-height: 24px; margin-bottom: 16px;">Please note: the code will be valid for the next 10 minutes.</p>
<p style="font-size: 16px; font-weight: normal; line-height: 24px; margin-bottom: 16px;">
If you didn&apos;t request this email, there&apos;s nothing to worry about - you can safely ignore it.
Expand Down
2 changes: 2 additions & 0 deletions platform/email/src/emailFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export const getOTPEmailContent = (
clientId: string,
state: string,
email: string,
passportURL: string,
params?: Partial<EmailTemplateParams>
): EmailContent => {
params = adjustEmailParams(params)
Expand All @@ -197,6 +198,7 @@ export const getOTPEmailContent = (
clientId,
email,
state,
passportURL,
params as EmailTemplateParams
)
}
Expand Down
2 changes: 2 additions & 0 deletions platform/email/src/jsonrpc/methods/sendOTPEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const sendOTPEmailMethodInput = z.object({
state: z.string(),
clientId: z.string(),
themeProps: EmailThemePropsSchema.optional(),
passportURL: z.string().url(),
})

export type sendOTPEmailMethodParams = z.infer<typeof sendOTPEmailMethodInput>
Expand All @@ -37,6 +38,7 @@ export const sendOTPMethod = async ({
input.clientId,
input.state,
input.emailAddress,
input.passportURL,
input.themeProps
)
const { env, notification, customSender } = getEmailContent({
Expand Down

0 comments on commit a88737c

Please sign in to comment.