CallumBoase / plasmic-supabase

GNU General Public License v3.0
7 stars 5 forks source link

Modify the way custom user metadata registration works to better support the "Low code" ethos #14

Closed CallumBoase closed 3 months ago

CallumBoase commented 3 months ago

PROBLEM: when defining custom metadata in SupabaseUserGlobalContext -> Signup method, the current method requires a user to specify an options object as per the supabase docs

While this works, it requires the user to go and reference the supabase JS docs, which doesn't match the ethos of low-code that this library is trying to achieve.

SOLUTION from @RyanMouritz

//sign up function
//signUp
      signup: async (email: string, password: string, successRedirect: string, emailRedirect?: string, userMetadata?: UserMetadata) => {
        try {
          const supabase = await createClient();
          let options = Object.assign({},
            userMetadata && { data: userMetadata },
            emailRedirect && { emailRedirectTo: emailRedirect },
          )
          const { error } = await supabase.auth.signUp({ 
            email, 
            password,
            options 
          });
          if (error) throw error;
          await getUserAndSaveToState();
          setError(null);
          //Redirect if needed
          if((successRedirect) && router) router.push(successRedirect);
          // There is potential to include a signup redirect here that would redirect to a page provided in an action parameter
          return true;
        } catch (e) {
          setError(getErrMsg(e))
          return false;
        }
      },

And registration

signup: {
      parameters: [
        {
          name: "email",
          type: "string",
        },
        {
          name: "password",
          type: "string",
        },
        {
          name:"successRedirect",
          type: "string"
        },
        {
          name: "emailRedirect",
          type: "string"
        },
        {
          name: "userMetadata",
          type: "object"
        }
      ],
    },
CallumBoase commented 3 months ago

Fixed by referenced PR. Closing issue