Dumping the netlify identity widget - using gotrue auth with email verification

  • Define an emailer.sdl with a type that takes what your input needs (probably just an email)
  • and a Mutation inviteUserByEmail that uses the type
  • Write a service called emailer.js that implements the inviteUserByEmail mutation
  • that should be
export const inviteUserByEmail = async ({ input }) => {
  const { data, error } = await supabaseAdmin.auth.api.inviteUserByEmail(
    input.email
  )
}
  • then this is just a GraphQL mutation that you invoke via a form submit pretty much the same way you would Create a Contact in the tutorial here: Saving Data | RedwoodJS Docs

  • except instead of creating a contact, you are inviting the user where the form submit sends the email address

1 Like

Thank you @dthyresson :pray: That works. Quite simple in the end :slight_smile:

1 Like

Hi @dthyresson Does this pattern look OK to you? The supabase api call is working but the createInvitedUser function isn’t getting called atm

(I tested that createInvitedUser works via http://localhost:8911/graphql)


Edit I got this working with the following – user created in the db with response from inviteUserByEmail

export const createInvitedUser = async ({ input }) => {
  // validate(input)
  console.log('createInvitedUser input', input)
  return await db.user.create({
    data: {
      ...input,
      account: {
        connect: {
          id: context.currentUser.accountId,
        },
      },
    },
  })
}

export const inviteUserByEmail = async ({ input }) => {
  const { data, error } = await supabaseAdmin.auth.api
    .inviteUserByEmail(input.email)
    .then((response) => {
      const uuid = response.data.id
      const email = response.data.email
      const input = (uuid, email)
      createInvitedUser({ input: { email: email, uuid: uuid } })
      return 'weird, get an error if this is excluded'
    })
}

@0x1a4f7d58 My question about the above example is in user.create the invited user is being connected to the current user – aren’t these different people?

Alice invites Bob and Bob is created but connected to Alice’s account

Also, just because someone is invited, does not mean they have accepted.

Instead, you could use Supabase’s new webhooks to trigger when a user has confirmed their invite, then post to a webhook serverless function that … well … wouldn’t user be created already by Supabase in their auth.users?

Instead might you to update your users table with a trigger from auth.users and then in the webhook, update to connect … well, I am not sure what connecting to an account means.

In any case, I think there are a few considerations to check with this flow.

Hi @dthyresson Thanks for your comments. Yes, in this case, an Account can have multiple users. So Alice creates an account and then invites her colleague Bob. I haven’t yet introduced Roles but intend to do so (e.g. Alice as Admin and Bob as User.)

Good to know about the webhooks! I’ll check those out. I had just started to think about how I could tell if Bob is confirmed or not… If I could update based on a trigger from auth.users that would be awesome.