ScottishRoss / little_victories

BSD 3-Clause "New" or "Revised" License
3 stars 5 forks source link

Enhancement: Add Twitter login #13

Open ScottishRoss opened 2 years ago

ScottishRoss commented 2 years ago

Along with Google Sign-In, users should be able to sign in with a Twitter account.

saksham-gt commented 2 years ago

Can I take this issue? @ScottishRoss

ScottishRoss commented 2 years ago

Of course, have fun my friend!

saksham-gt commented 2 years ago

@ScottishRoss, Twitter Developers project is asking me about the following details : Website URL Callback URL Terms of Service Privacy Policy

Could you comment the websites of the above required fields?

ScottishRoss commented 2 years ago

Website: https://www.littlevictories.app/ Privacy Policy: https://www.littlevictories.app/privacy-policy

I have applied for a Twitter Dev account to get the final URLs, though I'm not sure what the TOS URL is. When I get approved I will let you know.

saksham-gt commented 2 years ago

I think without the TOS we cannot access the email of the users associated with their Twitter account. How much time will it take till we get the TOS URL?

ScottishRoss commented 2 years ago

I'm not sure I can say. Having a quick look around, it may take a few days for approval. I was unaware of this step otherwise I would have done it before.

Can you give me a link to the documentation regarding the TOS URL? If that's something I have to generate I may be able to get it done faster, but the Callback URL would still be blocked until this approval.

saksham-gt commented 2 years ago

Actually, I have no idea how this TOS URL thing works. I didn't come across any documentation that says how to generate it. If I find one I'll let you know.

ScottishRoss commented 2 years ago

Thanks. If my dev account gets approved I'll have a look there. Unfortunately, there's not much more I can help you with until that happens. You can try and create one yourself and see if that gets approved first. Those details can be left out of the PR and I can add them in later.

ScottishRoss commented 2 years ago

Callback URL: https://little-victories-b2c60.firebaseapp.com/__/auth/handler.

TOS is a problem though. It looks like Twitter requires me to have TOS on how I use their email address, but this is a legal document that would be quite a headache to get. I am contacting Twitter to ask for support, and I've reached elsewhere.

ScottishRoss commented 2 years ago

TOS Link: https://www.littlevictories.app/terms-of-service

It will suffice for now. I think that's everything you need, @sudo-saksham?

saksham-gt commented 2 years ago

Yeah, I guess there's everything that's needed. If anything else is required I'll inform.

saksham-gt commented 2 years ago

Hey, I've enabled the Twitter login and added an apt button to login with twitter, but as I'm clicking to authorize the application I'm getting the following error :

Unable to process request due to missing initial state. This may happen if browser sessionStorage is inaccessible or accidentally cleared. Related screenshot is attached below. Error

saksham-gt commented 2 years ago

Ahh, I came to know that we need to have a custom domain for twitter_login dependency to work. How do I resolve it? I found this resource but couldn't understand it properly. Can you help me with this? @ScottishRoss

ScottishRoss commented 2 years ago

@sudo-saksham That link/image seems to be broken. Can you share again?

ScottishRoss commented 2 years ago

Interesting. According to a Firebase issue a lot of people are encountering this, and have been for months, but with no solution.

Though specifically to Twitter Auth this stack overflow answer may help?

https://stackoverflow.com/questions/65657437/flutter-twitter-auth-error-missing-initialstate

saksham-gt commented 2 years ago

After this, the application is crashing. It's like the app starts to build and it shows the splash screen and then suddenly it crashes.

saksham-gt commented 2 years ago

It shows me the following error and I don't know what went wrong? I didn't change anything in my AndroidManifest.xml file. Just made that change from Stack Overflow. And, after that even I removed that line, it's just showing me this error and the app builds, the splash screen appears and suddenly the app closes.

Installing build/app/outputs/flutter-apk/app.apk...                 5.5s
E/AndroidRuntime(17415): FATAL EXCEPTION: main
E/AndroidRuntime(17415): Process: com.saksham.littlevictories, PID: 17415
E/AndroidRuntime(17415): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.saksham.littlevictories/com.saksham.littlevictories.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.saksham.littlevictories.MainActivity" on path: DexPathList[[zip file "/data/app/~~wCbGAdzQei-sRdjzYdcDDQ==/com.saksham.littlevictories-A7ykcXcdTcWS6W_2GUSGCQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~wCbGAdzQei-sRdjzYdcDDQ==/com.saksham.littlevictories-A7ykcXcdTcWS6W_2GUSGCQ==/lib/arm64, /data/app/~~wCbGAdzQei-sRdjzYdcDDQ==/com.saksham.littlevictories-A7ykcXcdTcWS6W_2GUSGCQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
E/AndroidRuntime(17415):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3348)
E/AndroidRuntime(17415):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3596)
E/AndroidRuntime(17415):        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
E/AndroidRuntime(17415):        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(17415):        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(17415):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2067)
E/AndroidRuntime(17415):        at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(17415):        at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime(17415):        at android.app.ActivityThread.main(ActivityThread.java:7705)
E/AndroidRuntime(17415):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17415):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime(17415):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
E/AndroidRuntime(17415): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.saksham.littlevictories.MainActivity" on path: DexPathList[[zip file "/data/app/~~wCbGAdzQei-sRdjzYdcDDQ==/com.saksham.littlevictories-A7ykcXcdTcWS6W_2GUSGCQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~wCbGAdzQei-sRdjzYdcDDQ==/com.saksham.littlevictories-A7ykcXcdTcWS6W_2GUSGCQ==/lib/arm64, /data/app/~~wCbGAdzQei-sRdjzYdcDDQ==/com.saksham.littlevictories-A7ykcXcdTcWS6W_2GUSGCQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
E/AndroidRuntime(17415):        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
E/AndroidRuntime(17415):        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(17415):        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(17415):        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
E/AndroidRuntime(17415):        at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
E/AndroidRuntime(17415):        at android.app.Instrumentation.newActivity(Instrumentation.java:1254)
E/AndroidRuntime(17415):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3336)
E/AndroidRuntime(17415):        ... 11 more

@ScottishRoss

ScottishRoss commented 2 years ago

So it can't find MainActivity. Make sure that line hasn't been removed from AndroidManifest.xml

saksham-gt commented 2 years ago

I'm atttaching my AndoridManifest file. It looks fine to me, but I don't have much experience with handling XML file. As far as I know the MainActivity line is present. Could you confirm? @ScottishRoss AndroidManifest.txt

ScottishRoss commented 2 years ago

https://stackoverflow.com/questions/61046199/java-lang-runtimeexception-unable-to-instantiate-activity-in-flutter

Ah, I think I know what the problem might be. If you look at the last answer on this post it will be because this is renamed: com.example.appname

The app will be looking for dev.rhenderson.little_victories, but yours is named com.saksham.littlevictories

image

Your folder structure will need to look like this. Truthfully, this is a bit of a nightmare to do as I've done it once before. Every reference to dev.rhenderson.little_victories will need to be changed to com.saksham.littlevictories, and those changes cannot be included in the PR as it will require me to change it back. It's probably worth keeping it as the default one.

saksham-gt commented 2 years ago

So, can you share the firebase project with me as I need your google-services.json file and hence there won't be need to change it to com.saksham.littlevictories?

saksham-gt commented 2 years ago

Okay, so I changed the package name to dev.rhenderson.little_victories and it worked like magic, but still I'm facing that Unable to instantiate activity error when I use twitter_login package though when I used flutter_twitter_login it worked and authentication is running perfectly, but the problem is that it's not null safe. As of now I have used latter package as it's working.

Now, working on merging the database when there is already a user signed in with same email. If you have any resource that guides on how to do it would be great. @ScottishRoss

ScottishRoss commented 2 years ago

I think there's some code in the google_sign_in auth that might help with that. Though this article has a section for "link multiple providers": https://petercoding.com/firebase/2021/06/06/using-twitter-authentication-with-firebase-in-flutter/#link-multiple-auth-providers

saksham-gt commented 2 years ago

I integrated Twitter sign-in and it's working perfectly. But I'm facing this issue. Basically, if a user has already logged in with Google then logs out and logs in with Twitter then as we authorize if shows the error account-exists-with-different-credential but doesn't return the credentials of the account that already exists and since I have no information on what the existing account credentials are, therefore I have to ask the user for it's Google sign-in information again (just for the 1st time when the user signs in with Twitter after signing in with Google).

So, do you have any resource which could guide me on how to get the existing account user credentials? Or should I make the PR with the current situation?

ScottishRoss commented 2 years ago

@sudo-saksham create a PR targetting the TwitterAuth_28OCT21 branch. You've done a lot of work and deserve the Hacktoberfest PR, and we can continue working on it after.

saksham-gt commented 2 years ago

I've made this PR. It has got some merge conflicts. Please review it and let me know if something needs to be changed.