Ready to get started?

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

robot mascot smiling

Sending an Invitation to Join Our Organization

In this lesson, we'll begin our organization invite system by first adding the ability to send an invitation email to join our organization.

Published
Jan 20
Duration
13m 30s

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

Get the Code

Download or explore the source code for this lesson on GitHub

Repository

Ready to get started?

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.

  1. Commented 1 month ago

    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

    Please sign in or sign up for free to reply

    1. Commented 1 month ago

      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

      Please sign in or sign up for free to reply

      1. Commented 1 month ago

        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

        Please sign in or sign up for free to reply

        1. Commented 1 month ago

          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

          Please sign in or sign up for free to reply