Skip to content

Commit faf8107

Browse files
issuedatdnywhjoshenlim
authored
feat(auth): add account changes notifications template schemas (supabase#39899)
* feat(auth): add account changes notifications template schemas * add ability to enable/disable the security templates * layout tweaks * misc padding and spacing * filter out new templates for non-preview users * Fix premature error state when loading templates page --------- Co-authored-by: Danny White <[email protected]> Co-authored-by: Joshen Lim <[email protected]>
1 parent 95eedb9 commit faf8107

File tree

6 files changed

+463
-85
lines changed

6 files changed

+463
-85
lines changed

apps/studio/components/interfaces/Auth/AuthTemplatesValidation.tsx

Lines changed: 239 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { object, string } from 'yup'
2-
3-
import { DOCS_URL } from 'lib/constants'
42
import type { FormSchema } from 'types'
53

64
const JSON_SCHEMA_VERSION = 'http://json-schema.org/draft-07/schema#'
@@ -32,12 +30,10 @@ const CONFIRMATION: FormSchema = {
3230
},
3331
},
3432
validationSchema: object().shape({
35-
MAILER_SUBJECTS_CONFIRMATION: string().required('"Subject heading is required.'),
33+
MAILER_SUBJECTS_CONFIRMATION: string().required('Subject heading is required.'),
3634
}),
3735
misc: {
38-
iconKey: 'email-icon2',
39-
helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
40-
[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
36+
emailTemplateType: 'authentication',
4137
},
4238
}
4339

@@ -68,12 +64,10 @@ const INVITE: FormSchema = {
6864
},
6965
},
7066
validationSchema: object().shape({
71-
MAILER_SUBJECTS_INVITE: string().required('"Subject heading is required.'),
67+
MAILER_SUBJECTS_INVITE: string().required('Subject heading is required.'),
7268
}),
7369
misc: {
74-
iconKey: 'email-icon2',
75-
helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
76-
[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
70+
emailTemplateType: 'authentication',
7771
},
7872
}
7973

@@ -104,12 +98,10 @@ const MAGIC_LINK: FormSchema = {
10498
},
10599
},
106100
validationSchema: object().shape({
107-
MAILER_SUBJECTS_MAGIC_LINK: string().required('"Subject heading is required.'),
101+
MAILER_SUBJECTS_MAGIC_LINK: string().required('Subject heading is required.'),
108102
}),
109103
misc: {
110-
iconKey: 'email-icon2',
111-
helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
112-
[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
104+
emailTemplateType: 'authentication',
113105
},
114106
}
115107

@@ -141,12 +133,10 @@ const EMAIL_CHANGE: FormSchema = {
141133
},
142134
},
143135
validationSchema: object().shape({
144-
MAILER_SUBJECTS_EMAIL_CHANGE: string().required('"Subject heading is required.'),
136+
MAILER_SUBJECTS_EMAIL_CHANGE: string().required('Subject heading is required.'),
145137
}),
146138
misc: {
147-
iconKey: 'email-icon2',
148-
helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
149-
[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
139+
emailTemplateType: 'authentication',
150140
},
151141
}
152142

@@ -177,12 +167,10 @@ const RECOVERY: FormSchema = {
177167
},
178168
},
179169
validationSchema: object().shape({
180-
MAILER_SUBJECTS_RECOVERY: string().required('"Subject heading is required.'),
170+
MAILER_SUBJECTS_RECOVERY: string().required('Subject heading is required.'),
181171
}),
182172
misc: {
183-
iconKey: 'email-icon2',
184-
helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
185-
[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
173+
emailTemplateType: 'authentication',
186174
},
187175
}
188176
const REAUTHENTICATION: FormSchema = {
@@ -210,12 +198,229 @@ const REAUTHENTICATION: FormSchema = {
210198
},
211199
},
212200
validationSchema: object().shape({
213-
MAILER_SUBJECTS_REAUTHENTICATION: string().required('"Subject heading is required.'),
201+
MAILER_SUBJECTS_REAUTHENTICATION: string().required('Subject heading is required.'),
202+
}),
203+
misc: {
204+
emailTemplateType: 'authentication',
205+
},
206+
}
207+
208+
// Notifications
209+
const PASSWORD_CHANGED_NOTIFICATION: FormSchema = {
210+
$schema: JSON_SCHEMA_VERSION,
211+
id: 'PASSWORD_CHANGED_NOTIFICATION',
212+
type: 'object',
213+
title: 'Password changed notification',
214+
purpose: 'Notify a user when their password has been changed',
215+
properties: {
216+
MAILER_SUBJECTS_PASSWORD_CHANGED_NOTIFICATION: {
217+
title: 'Subject heading',
218+
type: 'string',
219+
},
220+
MAILER_TEMPLATES_PASSWORD_CHANGED_NOTIFICATION_CONTENT: {
221+
title: 'Message body',
222+
descriptionOptional: 'HTML body of your email',
223+
type: 'code',
224+
description: `
225+
- \`{{ .Email }}\` : The user's email address
226+
- \`{{ .Data }}\` : The user's \`user_metadata\`
227+
`,
228+
},
229+
},
230+
validationSchema: object().shape({
231+
MAILER_SUBJECTS_PASSWORD_CHANGED_NOTIFICATION: string().required(
232+
'Subject heading is required.'
233+
),
234+
}),
235+
misc: {
236+
emailTemplateType: 'security',
237+
},
238+
}
239+
240+
const EMAIL_CHANGED_NOTIFICATION: FormSchema = {
241+
$schema: JSON_SCHEMA_VERSION,
242+
id: 'EMAIL_CHANGED_NOTIFICATION',
243+
type: 'object',
244+
title: 'Email changed notification',
245+
purpose: 'Notify a user when their email address has been changed',
246+
properties: {
247+
MAILER_SUBJECTS_EMAIL_CHANGED_NOTIFICATION: {
248+
title: 'Subject heading',
249+
type: 'string',
250+
},
251+
MAILER_TEMPLATES_EMAIL_CHANGED_NOTIFICATION_CONTENT: {
252+
title: 'Message body',
253+
descriptionOptional: 'HTML body of your email',
254+
type: 'code',
255+
description: `
256+
- \`{{ .Email }}\` : The user's new email address
257+
- \`{{ .OldEmail }}\` : The user's old email address
258+
- \`{{ .Data }}\` : The user's \`user_metadata\`
259+
`,
260+
},
261+
},
262+
validationSchema: object().shape({
263+
MAILER_SUBJECTS_EMAIL_CHANGED_NOTIFICATION: string().required('Subject heading is required.'),
264+
}),
265+
misc: {
266+
emailTemplateType: 'security',
267+
},
268+
}
269+
270+
const PHONE_CHANGED_NOTIFICATION: FormSchema = {
271+
$schema: JSON_SCHEMA_VERSION,
272+
id: 'PHONE_CHANGED_NOTIFICATION',
273+
type: 'object',
274+
title: 'Phone changed notification',
275+
purpose: 'Notify a user when the phone number has been changed',
276+
properties: {
277+
MAILER_SUBJECTS_PHONE_CHANGED_NOTIFICATION: {
278+
title: 'Subject heading',
279+
type: 'string',
280+
},
281+
MAILER_TEMPLATES_PHONE_CHANGED_NOTIFICATION_CONTENT: {
282+
title: 'Message body',
283+
descriptionOptional: 'HTML body of your email',
284+
type: 'code',
285+
description: `
286+
- \`{{ .Email }}\` : The user's email address
287+
- \`{{ .Phone }}\` : The user's new phone number
288+
- \`{{ .OldPhone }}\` : The user's old phone number
289+
- \`{{ .Data }}\` : The user's \`user_metadata\`
290+
`,
291+
},
292+
},
293+
validationSchema: object().shape({
294+
MAILER_SUBJECTS_PHONE_CHANGED_NOTIFICATION: string().required('Subject heading is required.'),
295+
}),
296+
misc: {
297+
emailTemplateType: 'security',
298+
},
299+
}
300+
301+
const IDENTITY_LINKED_NOTIFICATION: FormSchema = {
302+
$schema: JSON_SCHEMA_VERSION,
303+
id: 'IDENTITY_LINKED_NOTIFICATION',
304+
type: 'object',
305+
title: 'Identity linked notification',
306+
purpose: 'Notify a user when a new identity has been linked to their account',
307+
properties: {
308+
MAILER_SUBJECTS_IDENTITY_LINKED_NOTIFICATION: {
309+
title: 'Subject heading',
310+
type: 'string',
311+
},
312+
MAILER_TEMPLATES_IDENTITY_LINKED_NOTIFICATION_CONTENT: {
313+
title: 'Message body',
314+
descriptionOptional: 'HTML body of your email',
315+
type: 'code',
316+
description: `
317+
- \`{{ .Email }}\` : The user's email address
318+
- \`{{ .Provider }}\` : The provider of the newly linked identity
319+
- \`{{ .Data }}\` : The user's \`user_metadata\`
320+
`,
321+
},
322+
},
323+
validationSchema: object().shape({
324+
MAILER_SUBJECTS_IDENTITY_LINKED_NOTIFICATION: string().required('Subject heading is required.'),
325+
}),
326+
misc: {
327+
emailTemplateType: 'security',
328+
},
329+
}
330+
331+
const IDENTITY_UNLINKED_NOTIFICATION: FormSchema = {
332+
$schema: JSON_SCHEMA_VERSION,
333+
id: 'IDENTITY_UNLINKED_NOTIFICATION',
334+
type: 'object',
335+
title: 'Identity unlinked notification',
336+
purpose: 'Notify a user when an identity has been unlinked from their account',
337+
properties: {
338+
MAILER_SUBJECTS_IDENTITY_UNLINKED_NOTIFICATION: {
339+
title: 'Subject heading',
340+
type: 'string',
341+
},
342+
MAILER_TEMPLATES_IDENTITY_UNLINKED_NOTIFICATION_CONTENT: {
343+
title: 'Message body',
344+
descriptionOptional: 'HTML body of your email',
345+
type: 'code',
346+
description: `
347+
- \`{{ .Email }}\` : The user's email address
348+
- \`{{ .Provider }}\` : The provider of the unlinked identity
349+
- \`{{ .Data }}\` : The user's \`user_metadata\`
350+
`,
351+
},
352+
},
353+
validationSchema: object().shape({
354+
MAILER_SUBJECTS_IDENTITY_UNLINKED_NOTIFICATION: string().required(
355+
'Subject heading is required.'
356+
),
357+
}),
358+
misc: {
359+
emailTemplateType: 'security',
360+
},
361+
}
362+
363+
const MFA_FACTOR_ENROLLED_NOTIFICATION: FormSchema = {
364+
$schema: JSON_SCHEMA_VERSION,
365+
id: 'MFA_FACTOR_ENROLLED_NOTIFICATION',
366+
type: 'object',
367+
title: 'MFA factor enrolled notification',
368+
purpose: 'Notify a user when a new MFA factor has been enrolled for their account',
369+
properties: {
370+
MAILER_SUBJECTS_MFA_FACTOR_ENROLLED_NOTIFICATION: {
371+
title: 'Subject heading',
372+
type: 'string',
373+
},
374+
MAILER_TEMPLATES_MFA_FACTOR_ENROLLED_NOTIFICATION_CONTENT: {
375+
title: 'Message body',
376+
descriptionOptional: 'HTML body of your email',
377+
type: 'code',
378+
description: `
379+
- \`{{ .Email }}\` : The user's email address
380+
- \`{{ .FactorType }}\` : The type of the newly enrolled MFA factor
381+
- \`{{ .Data }}\` : The user's \`user_metadata\`
382+
`,
383+
},
384+
},
385+
validationSchema: object().shape({
386+
MAILER_SUBJECTS_MFA_FACTOR_ENROLLED_NOTIFICATION: string().required(
387+
'Subject heading is required.'
388+
),
389+
}),
390+
misc: {
391+
emailTemplateType: 'security',
392+
},
393+
}
394+
395+
const MFA_FACTOR_UNENROLLED_NOTIFICATION: FormSchema = {
396+
$schema: JSON_SCHEMA_VERSION,
397+
id: 'MFA_FACTOR_UNENROLLED_NOTIFICATION',
398+
type: 'object',
399+
title: 'MFA factor unenrolled notification',
400+
purpose: 'Notify a user when an MFA factor has been unenrolled from their account',
401+
properties: {
402+
MAILER_SUBJECTS_MFA_FACTOR_UNENROLLED_NOTIFICATION: {
403+
title: 'Subject heading',
404+
type: 'string',
405+
},
406+
MAILER_TEMPLATES_MFA_FACTOR_UNENROLLED_NOTIFICATION_CONTENT: {
407+
title: 'Message body',
408+
descriptionOptional: 'HTML body of your email',
409+
type: 'code',
410+
description: `
411+
- \`{{ .Email }}\` : The user's email address
412+
- \`{{ .FactorType }}\` : The type of the newly enrolled MFA factor
413+
- \`{{ .Data }}\` : The user's \`user_metadata\`
414+
`,
415+
},
416+
},
417+
validationSchema: object().shape({
418+
MAILER_SUBJECTS_MFA_FACTOR_UNENROLLED_NOTIFICATION: string().required(
419+
'Subject heading is required.'
420+
),
214421
}),
215422
misc: {
216-
iconKey: 'email-icon2',
217-
helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
218-
[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
423+
emailTemplateType: 'security',
219424
},
220425
}
221426

@@ -226,4 +431,12 @@ export const TEMPLATES_SCHEMAS = [
226431
EMAIL_CHANGE,
227432
RECOVERY,
228433
REAUTHENTICATION,
434+
// Notifications
435+
PASSWORD_CHANGED_NOTIFICATION,
436+
EMAIL_CHANGED_NOTIFICATION,
437+
PHONE_CHANGED_NOTIFICATION,
438+
IDENTITY_LINKED_NOTIFICATION,
439+
IDENTITY_UNLINKED_NOTIFICATION,
440+
MFA_FACTOR_ENROLLED_NOTIFICATION,
441+
MFA_FACTOR_UNENROLLED_NOTIFICATION,
229442
]

0 commit comments

Comments
 (0)