Resources
Mailtrap.io - used to test our email sending locally with SMTP
Maily.to - used to generate our email notification's HTML markup
You can find the final markup used in this lesson on GitHub.
Join Adocasts Plus for $8.00/mo, or sign into your account to get access to all of our lessons.
In this lesson, we'll begin our organization invite system by first adding the ability to send an invitation email to join our organization.
Developer, dog lover, and burrito eater. Currently teaching AdonisJS, a fully featured NodeJS framework, and running Adocasts where I post new lessons weekly. Professionally, I work with JavaScript, .Net C#, and SQL Server.
Adocasts
Burlington, KY
Download or explore the source code for this lesson on GitHub
Mailtrap.io - used to test our email sending locally with SMTP
Maily.to - used to generate our email notification's HTML markup
You can find the final markup used in this lesson on GitHub.
Join Adocasts Plus for $8.00/mo, or sign into your account to get access to all of our lessons.
Join The Discussion! (4 Comments)
Please sign in or sign up for free to join in on the dicussion.
emilien
Hi Tom,
I was wondering how we can set custom error messages for specific validation rules inside the validator. In cases where the user is already a member of the organization, the default message is "The email has already been taken." However, I’d like to display a custom message instead, such as "This user is already part of this organization."
I'm trying to use i18n to translate it in french but I can find the right field + rule conbination as specified in the AdonisJS doc
Thanks !
Please sign in or sign up for free to reply
tomgobich
Hi emilien!
I actually haven't used the i18n AdonisJS package at all yet, probably should familiarize myself with it though haha.
The field target should just be
email.unique
, I believe. If you're trying to use the Detect User Locale middleware to automatically do this, it might be possible that the Inertia middleware is committing it's session store before the Detect User Locale middleware is able to apply the translations. Playing with the middleware order there, having inertia before the Detect User Locale insidestart/kernel.ts
, might help.You could also try passing it directly into the
validate
method, as shown here.When I have some free time, I'll play around with it a bit to see if I can get it figured out!
Please sign in or sign up for free to reply
emilien
Hi Tom,
I actually managed to make it work by reporting an custom error for the specific field with a rule, and use this rule inside my translation file. Not sure if it's the best solution, but it works for now 😅
Please sign in or sign up for free to reply
tomgobich
Hi emilien!! I think your linked repo is private, but I'm happy to hear you were able to find a solution! I just took a look into it and the target was
email.database.unique
where email is the validator field's name.The below, within
resources/lang/en/validator.json
, worked for me!You can find the logic used to find a translated message within the
I18nmessagesProvider
. Also, my initial thinking was incorrect. This is actually used immediately by the validator, not inside the middleware!Please sign in or sign up for free to reply