Closed Vortec4800 closed 6 years ago
Have you moved to using revocable sessions? Apparently this is a requirement to use ParseServer. https://parse.com/tutorials/session-migration-tutorial
Yes, I moved to the new sessions a while back now so all of my users have migrated at this point.
Hey, does anyone know if there's a way to upgrade to revokable sessions in the same build that switches to ParseServer? I somehow overlooked the new sessions and all my users are on legacy tokens, so this is all my fault, but I got close to a solution. I almost got it working with
[Parse enableLocalDatastore];
[Parse setApplicationId:clone? myParseAppId clientKey: myParseClientKey];
if ([User currentUser] && [User currentUser].sessionToken && ![[User currentUser].sessionToken hasPrefix:@"r:"]) {
NSLog(@"Fixing non-revokable session...");
[[User enableRevocableSessionInBackground] continueWithBlock:^id _Nullable(BFTask * _Nonnull task) {
if (!task.error) {
NSLog(@"Fixed session: %@", [User currentUser].sessionToken)
[self initializeParseWithServer:@"https://parseapi.back4app.com" cloneApp:NO];
}else{
NSLog(@"Error fixing session: %@", task.error.localizedDescription);
}
return nil;
}];
}else{
[self initializeParseWithServer:@"https://parseapi.back4app.com" cloneApp:NO];
}
using
-(void)initializeParseWithServer:(NSString*)server{
[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
configuration.applicationId = myParseAppId;
configuration.clientKey = myParseClientKey;
configuration.server = server;
configuration.localDatastoreEnabled = YES;
}]];
}
And I get an crash saying
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Task should be completed.'
This isn't surprising because reinitializing Parse SDK is undefined behavior, but I'm hoping a Parse engineer can help.
I would just spread it across multiple app launches. Check for a key in defaults. If it's not there, load the Parse.com SDK and migrate tokens, then set the key in defaults. Next time the app launches it will see the key and connect to your server instead.
That's a good idea. If it's a clean install, a subsequent date check for post-Parse.com will mean it can then decide whether to use Parse's token upgrade (won't work post-shutdown) or simply force a logout. This looks like the best option for me. Thanks for the hint!
I'm having same issue as initial post.
On our Android app it works seamlessly to switch between our self hosted parse server and parse.com backend but on iOS whenever moving between backend servers with the same database the PFUser nulls out. I've tried this with our beta setup and our prod setup.
The production app has revocable sessions.
I still haven't found a solution for this, I'm hoping it's just a bug in the SDK or something and there can be an update to it that fixes this.
I tried digging in and while it appeared that the user data isn't loading from however it saves, I'm not well-versed enough in the internals of the SDK to figure out what might be the issue.
I'm seeing some interesting results as I test a few theories. The upgrade path is working now but I still haven't nailed down exactly what is going on.
Are you using the same applicationId and only changing the server url? Originally I had a different applicationId for my hosted instance and keeping that constant might be what fixed it. Still a lot more testing required.
I've tried looking at the SDK internals quickly as well but couldn't determine if this theory has any merit.
This looks like the code that is causing the keychain to clear the data if applicationId is different.
(Around line 270)
if (task.result) {
if ([self.configuration.applicationId isEqualToString:task.result]) {
// Everything is valid, no need to remove, set applicationId here.
return nil;
}
[self.keychainStore removeAllObjects];
[self.keyValueCache removeAllObjects];
}
Ah no, I am using a different application ID. Per the Parse Server docs, you can use a simple name for the app ID instead of a full GUID like on Parse.com.
This does make sense though. I'll play with this and if this fixes it I'll be very grateful.
I debugged this exact case yesterday, different applicationId
was indeed the problem. After changing my Parse Server applicationId
to Parse.com one it started to work. I think more attention should be paid to this in migration tutorial(s).
Yeah - agreed. With the parse Android SDK the applicationId changing didn't have any impact and the migration tutorial gave me the impression that I could make up my own applicationId so I had generated a new UUID.
Hmm, I updated my application ID and all my keys (just to keep things consistent I suppose) on the server and client to match the Parse.com app, and it doesn't work. It does seem to try (I see the currentUser
value is loading and set properly), but I get an error when running a request on my server:
[Error]: invalid session token (Code: 209, Version: 1.14.2)
Sounds like some progress at least then. I'm not using a clientKey for my self hosted but I wouldn't think that would matter.
You're running against the same database for both? Obviously wouldn't work if you just had a snapshot version for self hosted. I'd probably debug to get the key on iOS and compare with session token on the server and see where that takes you.
Yes, both Parse.com and my Parse server are pointing to my own Mongo DB at this point.
Perhaps I'll try running the Parse server on my local machine and see if I can step through and find out where it's failing...
This issue has been automatically marked as stale because it has not had recent activity. If you believe it should stay open, please let us know! As always, we encourage contributions, check out the Contributing Guide
I'm finalizing our migration away from Parse.com, and the last major issue we have is that when the server changes, the currentUser isn't loaded.
After digging further, it seems like the user isn't loaded from (Core Data?) and the token isn't loaded from the keychain. I tried manually running [PFUser become:] on our new server with the session token but it reports that the token is invalid.
For some users this isn't a huge deal, we can have them log in again. I don't love this as I really want this to be transparent to the user, but if it's necessary then that's that.
I don't, however, know how we're going to deal with anonymous users. I can't ask them to log in again, and if I generate a new user they will lose all of their data.
How can I get around this? I'm using revocable sessions and I see all of the Session objects on our Mongo database in the dashboard, but it just seems like I can't use it. Unless there's another way to do this manually that I don't know about? How can I force the Parse SDK to use the existing session?