How to Update Credentials with Refreshtoken

Hi, when access user db synced i receive a invalid session, and comparing user.AccessToken == user.RefreshToken it’s diferent, and I want update user credential with refreshtoken ( Class User | Realm ) but i can’t find a method to do it.

I don’t want force logout and user made login again.

thanks

What method are you using when you get invalid session? Realm will automatically refresh credentials based on server error codes, so you should not experience disruptions in sync because of expired access tokens. The Access and Refresh token properties on the user object are expected to be different and it is not a bug that they are.

Hi @nirinchev ,
I receive Invalid Session in this two cases below, but it’s strange because i can access data with UserExtension = realmInstance.All().Where(u => u._id == realmUser.Id).FirstOrDefault();

the errors occurs in

**await App.AppEnvironmentService.SyncDB.RealmInstance.GetSession().WaitForDownloadAsync();**

	InvalidSession

  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Realms.Sync.SessionHandle.<WaitAsync>d__8.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at LexSemanticClient.ViewModel.LoginViewModel.<WaitSync>d__81.MoveNext() in C:\Users\scf\source\repos\Utilities\LexSemanticClient\LexSemanticClient\ViewModel\LoginViewModel.cs:line 628
   
   **await user.RefreshCustomDataAsync();**

   InvalidSession: invalid session: refresh token expired
   
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Realms.Sync.SyncUserHandle.<RefreshCustomDataAsync>d__10.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Realms.Sync.User.<RefreshCustomDataAsync>d__31.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at LexSemanticAppSyncPersistence.Database.<GetCurrentUserExtension>d__21.MoveNext() in C:\Users\scf\source\repos\Utilities\LexSemanticAppSyncPersistence\Database.cs:line 183

I think UserExtension = realmInstance.All().Where(u => u._id == realmUser.Id).FirstOrDefault(); is working because instance is created as Realm.GetInstance(RealmSyncConfig) , only first time open is made with await Realm.GetInstanceAsync(RealmSyncConfig) , i tried to use it but receive same Invalid Session.

@nirinchev i’m using .net sdk 10.5.0 , and I see new version 10.7.0 is deprecating GetSession(), i will update and see if this problem persists.

thanks

This looks like a yet-undiscovered bug, so I don’t think 10.7.0 will fix it, unfortunately.