Skip to content

Twitter OAuth signup fails if user has no email on their twitter account #2853

Closed

Description

@fortydegrees

Bug report

Describe the bug

If a twitter user doesn't have their email address connected to their twitter account, supabase's twitter OAuth integration fails on signup with the message "Error getting user email from external provider'.

To Reproduce

I used the nextjs-auth-tailwind example and selected 'twitter' as the OAuth provider.

Then set up my supabase project and followed the steps to add twitter OAuth.

When I sign up with a twitter account that has an email address connected, it works fine.

When I try and sign up with a twitter account that doesn't have an email address, I'm redirected back to the homepage with

?error=server_error&error_description=Error+getting+user+email+from+external+provider

appended to the URL. This is the same error that appears if you try and sign up with a fully-verified twitter account but don't have 'request email' enabled.

I have obviously enabled 'request email address' in my twitter OAuth settings, as supabase also fails if this isn't done. That said, it would be nice for this not to be necessary. Is this possible? Seems like it'd also fix this 'bug'.

Expected behavior

For the user to sign up normally. My app doesn't need a user's email, just their twitter account.

Additional context

I'm not sure if this is by design, but it is semi-breaking for my app as many twitter users don't have an email address. My app needs to be able to connect to the user's twitter account to look up lists and tweets on their behalf, and I can't do this if they don't have a verified twitter account.

Perhaps there may be a temporary fix if I'm able to change what supabase does under the hood to convert the twitter authorization to a supabase user. I'm not too familiar with supabase so not too sure how to do this. That said, would like it to work regardless (but understand it may break supabase based on design decisions).

If this isn't expected to be a super difficult fix, would appreciate being pointed in the right direction and can try and fix it myself (if it's even considered a bug)

Activity

  1. added
    bug
    on Aug 16, 2021
  2. sandbox-apps commented on Aug 17, 2021

    @sandbox-apps

    I have also investigated this but have no time to post and explain. But here it is.

    Problems:

    1. Some External Auth Provider doesn't require or provider email address
    2. Supabase looks like extremely rely on email as Unique Identifier of User (Very problematic)

    To explain:
    External auth provider nowadays doesn't require email for their sign up process. Example FB and Twitter doesn't require email, some user can sign up using phone numbers. Does this cause the bug explained by @fortydegrees above. This is very critical as I have encounter this issue when using firebase where I use security rules to require email but not knowing that emails are only really optional. The result? 1 to 3 stars rating from angry user for those who cant sign up because they dont have email address on their auth provider while others can sign up. This gives a bad impression to the app. And those people who cannot sign up are less likely to comeback again.

    What is problematic here?
    If supabase heavily rely on user email as a unique identifier of user from external auth. They are doing it wrong. External providers return UID instead that must be the one to be used instead of email as a identifier. Now, I wonder if supabase is really saving the external provider auth uid or just the email. Because if its not, then all the existing user has no UID saved on supabase

    In comparison with Firebase
    The user class of firebase auth has a list of provider field which is structured like this

    displayName → String? (The users display name.)
    email → String? (The users email address.)
    phoneNumber → String? (Returns the users phone number.)
    photoURL → String? (Returns a photo URL for the user.)
    providerId → String (The federated provider ID.)
    uid → String (The user's unique ID.)

    Note: all question mark are optional/nullable because firebase doesnt expect other providers to return this from authentication instead they focus on providerId and uid.

    providerId values are: 'facebook', 'twitter', 'google', 'github', 'apple', etc...
    while uid values are the uid of the user from the external providers.

    What is the importance of this two fields?
    Now if we signed in via facebook for example -> we can look up on this fields uid and providerId

    To know more about this: https://pub.dev/documentation/firebase_auth/latest/firebase_auth/User-class.html

    I feel like you feel overconfident about one liner sign up/sign in process and overlook this kind of mistakes.

  3. sandbox-apps commented on Aug 17, 2021

    @sandbox-apps

    To add on with this problem.
    https://github.com/supabase/supabase/issues/2556

    Hey @sandbox-apps - this is technically possible, as long as the user has the same email for all accounts (since this is the primary login mechanism).

    For example

    user logs in with email '[email protected]'
    user logs in with Facebook OAuth and their facebook account has the email '[email protected]'
    Both of these will return the same user uuid.

    Hey @sandbox-apps - this is technically possible, as long as the user has the same email for all accounts (since this is the primary login mechanism).

    This is where I first felt the concern where I have read this email for all accounts (since this is the primary login mechanism).
    I think this should be structured as
    Sign In via

    1. Email and Password -> email and password lookup -> return Supabase auth uid
    2. Facebook -> facebook will return the User UID -> UID and providerId (which is 'facebook') to lookup -> return Supabase auth uid
    3. Twitter -> twitter will return the User UID -> UID and providerId (which is 'twitter') to lookup -> return Supabase auth uid
    4. Google -> google will return the User UID -> UID and providerId (which is 'google') to lookup -> return Supabase auth uid
    5. Apple -> apple will return the User UID -> UID and providerId (which is 'apple') to lookup -> return Supabase auth uid
  4. sandbox-apps commented on Aug 17, 2021

    @sandbox-apps

    TLDR: all those who dont have email address on every social auth provider cannot use social auth provider right now.

  5. sandbox-apps commented on Aug 17, 2021

    @sandbox-apps
  6. fortydegrees commented on Aug 17, 2021

    @fortydegrees
    Author

    One way to turn this bug into a feature request could be to let us choose what supabase does with the received data from the OAuth provider - like what data to request and store about the user. I assume this is similar to what firebase does, e.g. being able to map fields to our supabase auth system.

  7. sandbox-apps commented on Aug 17, 2021

    @sandbox-apps

    I dont know about that @fortydegrees but firebase map its receive data automatically on auth system. But one thing you can do is use onAuthCreate on firebase functions to map it on firestore however you like

    Edit:
    I guess that is possible for every different set of permission you want to pass to access certain field/values but that would be very big task for supabase if ever.

    I still prefer to just get the bare minimum like provider, uid, name, displayName after that I will just implement form in my app to ask for different types of info

  8. shinriyo commented on Oct 24, 2021

    @shinriyo
    Contributor

    same error when I use GitHub.

  9. camiaei commented on Oct 27, 2021

    @camiaei

    I'm facing a similar issue: I want to use the Twitter OAuth Provider, but I don't want my users to be forced to show me their email address.

  10. kennethcassel commented on Nov 19, 2021

    @kennethcassel
    Contributor

    not using email as the unique identifier could also allow folks to use things like wallet addresses. Would love to sign up users without an email

  11. maximkott commented on Dec 16, 2021

    @maximkott

    Happens for me too when using GitHub as OAuth provider 😔

  12. maximkott commented on Dec 16, 2021

    @maximkott

    For me the issue with GitHub was because of a missing permission inside the GitHub Application. Just set the "email access" field to "read only" and it works as supposed.

  13. kiwicopple commented on Dec 28, 2021

    @kiwicopple
    Member

    this one is a duplicate of supabase/auth#214

    Closing in favour of the gotrue issue

  14. mijorus commented on Nov 4, 2022

    @mijorus
  15. nicitaacom commented on Nov 16, 2023

    @nicitaacom

    I have the same issue - I use twitter
    image

  16. nicitaacom commented on Nov 16, 2023

    @nicitaacom

    Guide how to fix this error if you use twitter provider

    Step 1 - https://developer.twitter.com/en

    image

    Step 2

    image

    Step 3

    image

    Step 4

    image

    To do this you need to deploy your app on vercel for example

    Step 5

    Then in your code

    const { error } = await supabaseClient.auth.signInWithOAuth({
            provider: "twitter",
            options: { redirectTo: `${location.origin}/auth/callback/oauth` },
          })
          if (error) throw error

    (auth)/auth/callback/oauth

    import supabaseAdmin from "@/libs/supabaseAdmin"
    import { getURL } from "@/utils/helpers"
    import { createRouteHandlerClient } from "@supabase/auth-helpers-nextjs"
    import { cookies } from "next/headers"
    import { NextResponse } from "next/server"
    
    export async function GET(request: Request) {
      const requestUrl = new URL(request.url)
      const code = requestUrl.searchParams.get("code")
    
      //If supabase put something in error_description - show it on error page
      const error_description = requestUrl.searchParams.get("error_description")
      if (error_description) {
        const supabase_error_description = encodeURIComponent(error_description)
        return NextResponse.redirect(`${requestUrl.origin}/error?error_description=${supabase_error_description}`)
      }
    
      // exchange cookies for session and set avatar url
      if (code) {
        const supabase = createRouteHandlerClient({ cookies })
        const response = await supabase.auth.exchangeCodeForSession(code)
        if (response.data.user && response.data.user.email) {
          // Insert row if user doesn't exist
          await supabaseAdmin.from("users").insert({
            id: response.data.user.id,
            username: response.data.user.user_metadata.name,
            email: response.data.user.email,
            email_confirmed_at: response.data.user.email_confirmed_at,
          })
    
          // Replace avatar_url if !avatar_url
          const { data, error: selectAvatarError } = await supabaseAdmin
            .from("users")
            .select("avatar_url")
            .eq("email", response.data.user.email)
            .single()
        if (selectAvatarError) throw selectAvatarError
          if (!data?.avatar_url) {
            await supabaseAdmin
              .from("users")
              .update({
                email_confirmed_at: response.data.user.updated_at,
                avatar_url: response.data.user.user_metadata.avatar_url,
              })
              .eq("id", response.data.user.id)
          }
        } else {
          const error_description = encodeURIComponent("No user found after exchanging cookies for registration")
          return NextResponse.redirect(`${requestUrl.origin}/error?error_description=${error_description}`)
        }
      }
      return NextResponse.redirect(`${getURL()}`)
    }
  17. magnussentio commented on Jul 11, 2024

    @magnussentio

    So this was never resolved correct? I'm not the most code savy but I encounter this same issue using WeWeb.io, a no code frontend that integrates with Supabase and Supabase Auth. I'm building an app specific to the Twitter (X) community, however, during debugging, I couldn't even log in to my own app because I don't have an email associated with my Twitter account (lol right). For creators like me, who currently rely on no-code solutions to move quickly, would love to use Supabase because of how friendly the pricing is, compared to other platforms like Xano (which are also more difficult to implement in my opinion). So is there any movement on no-email twitter login or is this officially dead?

  18. Silur commented on Aug 16, 2024

    @Silur

    30% of users on X do not have emails associated to their account.
    OAuth being unusable on 30% of the target platform means a non-functioning faulty product, it is not an edge-case that can be safely ignored for 3 years @kiwicopple @joshenlim

  19. hf commented on Aug 24, 2024

    @hf
    Contributor

    Hey folks! I understand your frustration as exemplified by this:

    it is not an edge-case that can be safely ignored for 3 years

    The team agrees with this. However, removing the dependence on email addresses is slowly in progress and we expect to ramp up and finish it in the next period. I can go in to why it's so challenging on our end, but we've already resolved most of the biggest challenges so there's not much more to do to lift the restriction.

    Thank you for being patient with us!

  20. Sequoya42 commented on Sep 21, 2024

    @Sequoya42

    @hf Any update on this?
    Any ETA?

    thank you

  21. quantumdominik commented on Sep 30, 2024

    @quantumdominik

    @hf any updates here? Need this feature bad.

  22. Mumbo-Jumbo-3 commented on Oct 27, 2024

    @Mumbo-Jumbo-3

    @hf pls ser no require email

  23. exitss commented on Feb 19, 2025

    @exitss

    @hf please stop forcing email.

  24. matheuseabra commented on Apr 20, 2025

    @matheuseabra

    Honestly this bug has been around for +4 years this is just ridiculous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions