supabase / auth-js

An isomorphic Javascript library for Supabase Auth.
MIT License
357 stars 161 forks source link

Unable to pass shouldCreateUser: false when using generateLink #358

Open chrisb2244 opened 2 years ago

chrisb2244 commented 2 years ago

Feature request

Is your feature request related to a problem? Please describe.

If I use the auth.signIn(...) function, I can prevent the creation of new users by passing shouldCreateUser: false. It doesn't appear to be possible to do the same if instead I want to use auth.api.generateLink('magiclink', email, redirectTo).

Describe the solution you'd like

Addition of a parameter (probably in the options) for generateLink to allow the prevention of new user creation.

Describe alternatives you've considered

I can use the auth.signIn({email}, { shouldCreateUser: false, redirectTo, ...options }) function, but then I can't generate the email formatting as I might prefer. Perhaps it's possible to workaround by first checking the existence of a user, and then rejecting before calling generateLink, but it would be nice to have the magiclink able to receive the same options as the signIn function.

monicakh commented 2 years ago

@supabase/auth-team Assigning this to the PIC of the Auth team to take care of this.

activenode commented 12 months ago

I'm confused that the related PR was closed. I'll take it up I guess.

activenode commented 12 months ago

FYI for those who need a workaround:

  1. The easiest option without having to create an RPC is to delete the user after creation immediately.
  2. OR create an RPC like here https://github.com/orgs/supabase/discussions/1282#discussioncomment-1674133
const { data } =  supabase.auth.admin.generateLink(...);

if (data.properties) {
  const user = data.user;
  const { hashed_token, verification_type } = data.properties;

  if (verification_type === 'signup') {
   await supabase.auth.admin.deleteUser(user.id);
   return; // dont do anything else
  }
}
ham-evans commented 2 months ago

Any updates to this? Seems like an easy fix but current functionality is super annoying