vercel / nextjs-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with Next.js.
https://subscription-payments.vercel.app/
MIT License
5.83k stars 1.19k forks source link

Question / issue with Update Email functionality? #220

Closed nate-oo closed 8 months ago

nate-oo commented 1 year ago

Hi guys!

First thing is this is an awesome repo! Great work everyone!

Disclaimer: Forgive me if submitting an issue is not the right place for a question.

I'm new to programming and am going through the code and working on understanding all the logic and actions that are taking place.

These may not be issues and I haven't actually cloned this repo and tested things yet. Just trying to understand it all.

My questions

  1. What exactly happens when the function in the below code is called (what happens in Supabase and Stripe)?
  2. Does this also trigger an update to update their email address on the customer Object in Stripe? Should it or does it not create issues if there is a different email address on the 'users' table in Supabase vs the email address on the customer object in Stripe?
  3. What is the impact on future logins for the user if you have social providers setup (say Google and Facebook) and they try to login again but choose to use Google instead of say email+password and each of those methods have different email addresses?
  4. What is the impact on future checkout sessions if there is a different email address on the 'users' table in Supabase vs the email address on the customer object in Stripe?

The Code: Found under app/account/page.tsx

const updateEmail = async (formData: FormData) => {
    'use server';

    const newEmail = formData.get('email') as string;
    const supabase = createServerActionClient<Database>({ cookies });
    const { error } = await supabase.auth.updateUser({ email: newEmail });
    if (error) {
      console.log(error);
    }
    revalidatePath('/account');
  };

Thanks! Nate

scottklein7 commented 8 months ago

@nate-oo Great questions Nate, did you get the answers to these?

nate-oo commented 8 months ago

@scottklein7 I did not.

I figured I would just Close it was sitting as Open for such a long time and make it one less Open Issue/Question in the repo. I know the contributors are busy building awesome stuff at Supabase, Stripe, and Vercel/Nextjs.

I also haven't looked into this deeply on my own yet. But here are my initial thoughts.

Friendly Disclaimer: This could be wrong as I haven't spent the time yet and am not at that stage of my app.

  1. I believe that the updateEmail Server Action will only update the email address on the Supabase managed table auth.user.
  2. Unless I am missing something, I did not see code anywhere else that updates the email on the user's related record on the Stripe Customer object. In my opinion, I think it probably should so those stay in sync with each other.
  3. If the email address on their social login is the same as the email address on their email+password login, I believe Supabase might automagically link those together. If the email addresses are different, I believe it will create a different (i.e. duplicate) user in Supabase. I don't know if there really is a way you can prevent that and I don't know how to merge those users in Supabase if that happens. My initial thoughts are that I probably will just add some additional text to my sign in form below the sign in button that says something to the user about this.
  4. I believe there is no technical impact if the email addresses differ from the Supabase auth.users email value and the email value of their related Stripe Customer record. I believe the Stripe Customer record's email is what will show as greyed out in checkout. So at most I think this would create confusion for the user. Say for instance, on the Account page of your app they update their email. The Server Action updates it. They now have a different email than what is on their related Stripe Customer record because the code doesn't update the user's related Stripe Customer record's email value. NOW, they then make it to checkout and the email greyed out in Checkout show's their old email because their related Stripe Customer record's email value was never updated. This may create some confusion for the user.

Again could be missing things or wrong on some things here. Hopefully this is some food for further thought.