Overview
Email invites allow users to invite additional users to their tenants. When a user invites another user, Nile Auth:- Sends an invite email using your configured SMTP server.
- Grants access to the user after they click the invite link.
Prerequisites
- A configured SMTP server is required to send verification emails. You can set this up in the Nile Auth UI under Tenants & Users -> Configuration -> Email templates.
- A web server configured to handle Nile Auth requests and serve html.
Implementation
1
Install dependencies
2
Your application must expose API routes to handle authentication operations.Create a folder called Create following files handle the calls to your server, as well as expose the
api
under the app
folder and a folder called [...nile]
under it:nile
instance to your application:app/api/[...nile]/nile.ts
app/api/[...nile]/route.ts
3
List invites for a user
4
Basic invite user action
Based on the current context, invite the new user
5
Callback after invite
For completeness, it is possible that an existing user invited a brand new user. Because user authorization/authentication is separate from tenant membership, and even invites exist outside of a user account, you may need to prompt the user to create an account that they are able to use.In the below sample code, the
/your-callback-handler
could check if the user has logged in by virtue of the nile.users.getSelf()
function.If they are not logged in, send them to a sign up page for user creation or sign in.If they are logged in, we check to be sure they are the same user. If not, they need to switch users (their current signed in user does not have access to the tenant, after all)Lastly, if they are signed in as the user that was invited, they can see a list of invites on that tenant.Nile-auth email address are an exact match. Some email providers (like gmail) will allow receiving emails that don’t exactly match, eg (my.cool.email@gmail.com can receive mail from mycoolemail@gmail.com). In nile-auth, those are considered two separate users.