mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Allow DDP client to register onDisconnect callback.
accounts-base uses this to handle disconnects due to users being intentionally logged out.
This commit is contained in:
@@ -112,6 +112,13 @@ Accounts.callLoginMethod = function (options) {
|
||||
}});
|
||||
}
|
||||
};
|
||||
|
||||
Meteor.connection._onDisconnect = function (reason) {
|
||||
var loggedOutReasons = ["logged_out", "token_expired",
|
||||
"user_deleted", "token_deleted"];
|
||||
if (_.indexOf(loggedOutReasons, reason) !== -1)
|
||||
makeClientLoggedOut();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -162,6 +169,7 @@ makeClientLoggedOut = function() {
|
||||
unstoreLoginToken();
|
||||
Meteor.connection.setUserId(null);
|
||||
Meteor.connection.onReconnect = null;
|
||||
Meteor.connection._onDisconnect = null;
|
||||
};
|
||||
|
||||
makeClientLoggedIn = function(userId, token, tokenExpires) {
|
||||
@@ -189,7 +197,6 @@ Meteor._logoutAllOthers = function (opts, callback) {
|
||||
}
|
||||
Meteor.apply('_logoutAllOthers', [opts], { wait: true },
|
||||
function (error, result) {
|
||||
console.log("logged out others");
|
||||
if (error) {
|
||||
callback && callback(error);
|
||||
} else {
|
||||
|
||||
@@ -1324,10 +1324,7 @@ _.extend(Connection.prototype, {
|
||||
_livedata_disconnected: function (msg) {
|
||||
var self = this;
|
||||
var reason = msg.reason;
|
||||
if (reason === "logged_out" || reason === "token_expired") {
|
||||
self.setUserId(null);
|
||||
self.onReconnect = null;
|
||||
}
|
||||
self._onDisconnect && self._onDisconnect(reason);
|
||||
},
|
||||
|
||||
_livedata_error: function (msg) {
|
||||
|
||||
Reference in New Issue
Block a user