Invite user by e-mail with Supabase Auth

Hello,

I want to make simple form from which Admin will be able to invite some user by email, same way as you can invite user from Supabase Studio:

Form is simple:

Link in received email need to redirect to Sign Up page.

This invitation from Supabase sent only Confirmation link that only confirm the user but user dont have any login info and dont know how to login.

Thank you in advance

Hi Zoran :waving_hand:,

You can get something close to this flow, but it would not be “just a simple form” because you need some custom logic on top of Supabase’s default confirmation email.​

The general idea would be:

  • Use the form in WeWeb to call a Supabase Edge Function / backend endpoint that creates the user and generates a magic link or one‑time token for that email.​
  • Send a custom email where the button points to your WeWeb signup page (for example https://your-app.com/signup?token=...), and on that page you read the token, validate it with Supabase, and then let the user set their password and access the app.

You could experiment with something along those lines and see if it fits your use case, let me know if this helps :slight_smile:

1 Like

I looked into this a bit as well. Haven’t found a solution. Keen to see if you find a solution.

1 Like

Hello,

The simplest solution for me will be to keep using Send invitation from Supabase but in email template to implement link to my Sign Up page. Two options:

  1. To reed sign up page from .env or somwhere else in Supabase

  2. Sign Up link to be hardcoded in email template.

I dont get it 2 things.

  1. Why is so scary link to sign up page to be hard coded in email template, because i have read that this is not recomended. My sign up page will be public anyway, so i dont see a problem.

  2. Concept of Supabase invitation with link, which when user click it, it just confirm in Supabase that user has clicked it, but user dont have any login info. Probably i am missing something.

About Edge Function, i have just run succesfully Edge Function that send emails but not creating account on Supabase.

It was tested just with api link in browser but can be trigered through WeWeb if it is nececary. Just dont sure how to sent email address to Function and Function to read it.

Hi,

This is how I personnaly implemented it:

1. Create an edge function that handles the form’s user data (name, email, etc.)

Use something like:

//Create invitation record

const includesEditor = frontUrl.toLowerCase().includes('editor');
const redirectUrl = includesEditor 
  ? `${frontUrl}?invitation_id=${invitation.id}`
  : `${frontUrl}/sign-up?invitation_id=${invitation.id}`;

const { data: inviteData, error: inviteError } = await supabaseAdmin.auth.admin.inviteUserByEmail(normalizedEmail, {
  redirectTo: redirectUrl
});

//then create the associated profile

I have an invitation table to manage expiration, and my frontend URL is a record from a metadata table in Supabase.

2. Customize the invite user email template

In my invite user email template, I’ve included:

<div style="text-align: center; margin: 32px 0;">
  <a href="{{ .ConfirmationURL }}" style="display: inline-block; background-color: #111827; color: white; text-decoration: none; padding: 12px 24px; border-radius: 12px; font-weight: 500; font-size: 14px; font-family: Arial, sans-serif; border: 1px solid #111827;">
    Accepter l'invitation
  </a>
</div>

3. Handle the redirect

When the user clicks the link, they’re redirected to the URL with a token (they are now logged in).

4. Create a sign-up page

I’ve created a sign-up page where, on load, I query the invitation from the query parameter:

On this page, I ask for the user’s information (including password):

5. Update user data on submission

When the user submits, I call another edge function to update the password, invitation, etc.:

// Update user password
const { error: updateError } = await supabase.auth.admin.updateUserById(invitation.profiles.id, {
  password: password
});

Then redirect the user to the index page.

3 Likes

Hello Hugo-OC,

Nice Job. I just want to ask where did you find Supabase Select invitation and Supabase Select profile in your workflow?

Hey,

I made some custom tables called profiles & invitations.

Then use the standard Weweb action called « select »
( I renamed them for clarity)

2 Likes