Fix token refresh and session bugs in chrome debugging (#831)
This commit is contained in:
parent
70437745f0
commit
b2da398559
|
@ -141,7 +141,7 @@ function serialize(realmId, value) {
|
|||
return {type: objectTypes.DICT, keys, values};
|
||||
}
|
||||
|
||||
function deserialize(realmId, info) {
|
||||
export function deserialize(realmId, info) {
|
||||
let type = info.type;
|
||||
let handler = type && typeConverters[type];
|
||||
if (handler) {
|
||||
|
|
|
@ -20,12 +20,13 @@
|
|||
|
||||
import { keys, objectTypes } from './constants';
|
||||
import { getterForProperty, createMethods } from './util';
|
||||
import { deserialize } from './rpc';
|
||||
|
||||
export default class Session { }
|
||||
|
||||
Object.defineProperties(Session.prototype, {
|
||||
url: getterForProperty('url'),
|
||||
state: getterForProperty('state')
|
||||
url: { get: getterForProperty('url') },
|
||||
state: { get: getterForProperty('state') }
|
||||
});
|
||||
|
||||
createMethods(Session.prototype, objectTypes.SESSION, [
|
||||
|
@ -42,7 +43,8 @@ export function createSession(realmId, info) {
|
|||
|
||||
sessionProxy[keys.id] = info.id;
|
||||
sessionProxy[keys.type] = objectTypes.SESSION;
|
||||
Object.assign(sessionProxy, info.data);
|
||||
sessionProxy.user = deserialize(realmId, info.data.user);
|
||||
sessionProxy.config = deserialize(realmId, info.data.config)
|
||||
|
||||
return sessionProxy;
|
||||
}
|
|
@ -58,10 +58,18 @@ function authenticateRealm(user, fileUrl, realmUrl) {
|
|||
if (response.status != 200) {
|
||||
//FIXME: propagate error to session error handler
|
||||
} else {
|
||||
return response.json().then((body) => {
|
||||
parsedRealmUrl.set('pathname', body.access_token.token_data.path);
|
||||
let session = user._sessionForOnDiskPath(fileUrl);
|
||||
session._refreshAccessToken(body.access_token.token, parsedRealmUrl.href);
|
||||
return response.json().then(function(body) {
|
||||
// Look up a fresh instance of the user.
|
||||
// We do this because in React Native Remote Debugging
|
||||
// `Realm.clearTestState()` will have invalidated the user object
|
||||
let newUser = user.constructor.all[user.identity];
|
||||
if (newUser) {
|
||||
let session = newUser._sessionForOnDiskPath(fileUrl);
|
||||
if (session) {
|
||||
parsedRealmUrl.set('pathname', body.access_token.token_data.path);
|
||||
session._refreshAccessToken(body.access_token.token, parsedRealmUrl.href);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -66,7 +66,11 @@ module.exports = {
|
|||
TestCase.assertEqual(session.state, 'active');
|
||||
|
||||
// give the session enough time to refresh its access token and bind itself
|
||||
return wait(500).then(() => {
|
||||
let timeout = 500;
|
||||
if (typeof window !== 'undefined') {
|
||||
timeout = 2500; // need a longer timeout under React Native because remote debugging
|
||||
}
|
||||
return wait(timeout).then(() => {
|
||||
TestCase.assertEqual(session.url, `realm://localhost:9080/${user.identity}/myrealm`);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue