Comments (18)
FirebaseApp.Create() will create the default app, you need to create a named secondary app using FirebaseApp.Create(options, name) see https://firebase.google.com/docs/reference/unity/class/firebase/firebase-app#class_firebase_1_1_firebase_app_1a39a702e1912ab6b708600b03bd955f4d
Here's an example:
https://github.com/firebase/quickstart-unity/blob/master/auth/testapp/Assets/Firebase/Sample/Auth/UIHandler.cs#L97
from firebase-unity-sdk.
Hi @initfusion, you can start from this doc, which introduces how to link multiple auth providers to one account in Unity. You can also find related docs for other platforms under iOS / Android / Web and C++.
Hope this helps.
from firebase-unity-sdk.
Hi @cynthiajoan, this doc is not enough for solving conflicts. Because the credentials which I linking is having an existing account so we have to delete the new account first. After that, we can link.
I have followed the doc https://firebase.google.com/docs/auth/web/account-linking
// Get reference to the currently signed-in user
var prevUser = auth.currentUser;
// Sign in user with another account
auth.signInWithCredential(credential).then(function(user) {
console.log("Sign In Success", user);
var currentUser = user;
// Merge prevUser and currentUser data stored in Firebase.
// Note: How you handle this is specific to your application
// After data is migrated delete the duplicate user
return user.delete().then(function() {
// Link the OAuth Credential to original account
return prevUser.linkWithCredential(credential);
}).then(function() {
// Sign in with the newly linked credential
return auth.signInWithCredential(credential);
});
}).catch(function(error) {
console.log("Sign In Error", error);
});
But the above code is in javascript.
In c# how to store prevUser? when I have signInWithCredantial I am lost the current user.
from firebase-unity-sdk.
Hi @initfusion, if I understand correctly, in Unity/C#, we have this example maybe can solve your problem:
Unity account linking
// Gather data for the currently signed in User.
string currentUserId = auth.CurrentUser.UserId;
string currentEmail = auth.CurrentUser.Email;
string currentDisplayName = auth.CurrentUser.DisplayName;
System.Uri currentPhotoUrl = auth.CurrentUser.PhotoUrl;
// Sign in with the new credentials.
auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
if (task.IsCanceled) {
Debug.LogError("SignInWithCredentialAsync was canceled.");
return;
}
if (task.IsFaulted) {
Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
// TODO: Merge app specific details using the newUser and values from the
// previous user, saved above.
});
You can grab prevUser by auth.CurrentUser before signInWithCredantial.
Let me know if that works for you.
from firebase-unity-sdk.
Hi @cynthiajoan
Yes, I have done that way but after doing signInWithCredantial the prevUser which I have grabbed previously is also changed to the new user.
I think its sync new user to all its existing user instances.
from firebase-unity-sdk.
Hi
This is I am trying
var credential = EmailAuthProvider.GetCredential(email, password);
auth.CurrentUser.LinkWithCredentialAsync(credential).ContinueWithOnMainThread(task =>
{
if (task.IsCanceled)
{
Debug.Log("Cancel");
}
if (task.IsFaulted)
{
Debug.Log("Faulted");
var currentUser = auth.CurrentUser;
otherAuth.SignInWithCredentialAsync(credential).ContinueWithOnMainThread(linkTask =>
{
Debug.Log("Current: " + currentUser.UserId);
Debug.Log("New: " + linkTask.Result.UserId);
// Here both current and new have the same user.
});
}
if (task.IsCompleted)
{
Debug.Log("Completed");
}
});
from firebase-unity-sdk.
HI @initfusion ,
as per @cynthiajoan suggestion, have you tried caching the individual fields you need before executing the SignInWithCredentialAsync
? The JavaScript and Unity APIs will be slightly different.
--Patrick
from firebase-unity-sdk.
Hi @patm1987,
Yes, I can cache the individual fields but I need the previous user to link the user.
Without a previous user, I can't call the LinkWithCredantials.
from firebase-unity-sdk.
With the Unity API, you just need the credential of the account you want to link with the current one (ie: if your continuation from LinkWithCredentialAsync
succeeds, you should have linked accounts). You can get more information here:
https://firebase.google.com/docs/reference/unity/class/firebase/auth/firebase-user#linkandretrievedatawithcredentialasync
Let me know if it's not the case, but you should be able to verify that the merger worked in your firebase authentication dashboard (in console.firebase.google.com).
from firebase-unity-sdk.
Hi @patm1987
Yes, it's not the case, Link account is working properly when there is no error when link.
But if there is an error (ie: if the credential which is I am going to merge is already having an account).
In that case, I have to delete the existing account. for delete existing account I have to SignIn so I can get the user and using that user I can delete.
if there is another way to solve merge conflicts then let me know.
Let me know if you still not understand my problem.
from firebase-unity-sdk.
@initfusion it looks like you've found a problem with both the C++ and Unity SDKs here. You're right that it's not currently possible to copy the FirebaseUser object in the C# API which is an issue in the case you've described where you want to:
- Cache the current user's auth token
- Attempt to sign in with credentials (e.g email / password) and if that results in a different user, delete the other user's account.
- Link the credentials (email / password) with the current user's account
However, I think it's possible to do this with multiple FirebaseApp objects instead:
- Create a secondary FirebaseApp object and a FirebaseAuth object from that (e.g
otherAuth
) - Then if credential linking fails with
FirebaseAuth.DefaultInstance.CurrentUser
, sign-in tootherAuth
with the credentials - Delete
otherAuth.CurrentUser
- Try linking credentials on
FirebaseAuth.DefaultInstance.CurrentUser
again
from firebase-unity-sdk.
Thanks for understanding my problem.
I was also tried with multiple Firebase objects but still not able to get or cache the current user's auth token.
Here is my code
otherAuth = FirebaseAuth.GetAuth(FirebaseApp.Create(AppOptions.LoadFromJsonConfig(conf.text)));
Now I am trying this but still, both are the same.
var credential = EmailAuthProvider.GetCredential(email, password);
auth.CurrentUser.LinkAndRetrieveDataWithCredentialAsync(credential).ContinueWithOnMainThread(task =>
{
if (task.IsCanceled)
{
Debug.Log("Cancel");
}
if (task.IsFaulted)
{
Debug.Log("Faulted");
otherAuth.SignInWithCredentialAsync(credential).ContinueWithOnMainThread(linkTask =>
{
Debug.Log("Current: " + auth.CurrentUser.UserId);
Debug.Log("New: " + otherAuth.CurrentUser.UserId);
// Here both current and new have same user..
});
}
if (task.IsCompleted)
{
Debug.Log("Completed");
}
});
from firebase-unity-sdk.
Thank you very much, using a secondary app solve my problem in all the methods except phone auth.
Now I am facing a new issue when link phone credentials. If phone auth link fails then I have used the same way to solve merge conflict.
- First, I copy the credentials of phone auth after auto verification completed
var phoneAuthProvider = PhoneAuthProvider.GetInstance(_auth);
phoneAuthProvider.VerifyPhoneNumber(phoneNumber, PhoneAuthTimeoutMs, null,
cred =>
{
_phoneAuthCredentials = cred;
},
- After that I linked the credentials to current user.
_user.LinkWithCredentialAsync(_phoneAuthCredentials).ContinueWithOnMainThread(HandleLinkWithUser);
- Now I get merge error
- After that, if I sign with that credentials I am getting "Phone auth code expire" error.
_otherAuth.SignInWithCredentialAsync(_phoneAuthCredentials).ContinueWithOnMainThread(HandleMergeConflict);
from firebase-unity-sdk.
After deleting the other phone auth account could you run through the VerifyPhoneNumber() step again ? I know it's a little irritating for the user but I'm sure you can pop up a message explaining what happened (e.g there was a duplicate account).
from firebase-unity-sdk.
This is not a proper way, because I need to VerifyPhoneNumber()
3 times.
- First, When linking the account first time.
- Second, When sigh in and delete the account
- Third, When linking again.
It's very irritating for the user. My testing phone numbers are work but others do not work.
from firebase-unity-sdk.
@initfusion I see what you mean, that is a pain. We'll try to get a fix out soon.
from firebase-unity-sdk.
Hi @stewartmiles,
May I know ETA for this issue?
from firebase-unity-sdk.
@initfusion we don't have a timeline for the change yet. I took a quick look at it last week and it's a non-trivial change to the way we store user data at the moment in the C++ SDK.
from firebase-unity-sdk.
Related Issues (20)
- [Bug] iOS crashes when Google sign in is not enabled HOT 2
- [Bug] SignIn With Facebook Exception: Bad access token: {"code":190,"message":"Invalid OAuth access token - Cannot parse access token"} HOT 2
- [Bug] SIGSEGV - Pure virtual function called! HOT 9
- [Bug] SIGSEGV - firebase::Mutex::Acquire() HOT 2
- [Bug] SIGSEGV - FORTIFY: pthread_mutex_lock called on a destroyed mutex (0x<sanitized>) HOT 2
- [Bug] AppCheck fails in debug environment with Firebase 11.9.0 HOT 12
- [Bug] Undefined symbol errors with Firebase SDK v 11.9.0 HOT 1
- [FR]: Add ReadOnlySpan-based overload for FirebaseAnalytics.LogEvent HOT 2
- [Bug] Firebase Messaging & Unity 6 - Not receiving notifications on Android HOT 8
- Firebase HOT 3
- [Question] INVALID_APP_ID error on Android HOT 7
- [Question] i don't know why please check URL HOT 4
- [Bug] DllNotFoundException: FirebaseCppApp-11_6_0 in Windows 10 HOT 8
- [Bug] Persistent connection error thrown when using Unity 2022 on Mac HOT 3
- [Bug] Problem with dependency resolution for Android and Unity 6000.0.1 HOT 10
- [Bug] Invalid mainTemplate.gradle for Unity 6000.0 HOT 7
- [Bug] Crash [libFirebaseCppApp-12_0_0.so] firebase::Mutex::Acquire() HOT 4
- [Question] Firebase - NoClassDefFoundError at startup HOT 3
- [Bug] Processing Libraries from Forced Resolution popup won't disappear HOT 1
- [Question] Firestore throws "Cursor has too many values" exception when running an aggregate count query that starts at a specific document HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firebase-unity-sdk.