Ready to get started?

Join Adocasts Plus for $8/mo, or sign into an existing Adocasts Plus account, to get access to all of our lessons.

robot mascot smiling

Sending an Invitation to Join Our Organization

@tomgobich
Published by
@tomgobich
In This Lesson

We'll begin our organization invite system by first adding the ability to send an invitation email to join our organization.

Join the Discussion 4 comments

Create a free account to join in on the discussion
  1. @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 !

    1
    1. Responding to emilien
      @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 inside start/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!

      1
      1. Responding to tomgobich
        @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 šŸ˜…

        1
        1. Responding to emilien
          @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!

          {
            "shared": {
              "messages": {
                "email.database.unique": "This is from the translation"
              }
            }
          }
          Copied!

          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!

          1