-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added in Meteor.loggingOut() and related Blaze helpers. #8271
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,8 @@ export class AccountsClient extends AccountsCommon { | |
constructor(options) { | ||
super(options); | ||
|
||
this._loggingIn = false; | ||
this._loggingInDeps = new Tracker.Dependency; | ||
this._loggingIn = new ReactiveVar(false); | ||
this._loggingOut = new ReactiveVar(false); | ||
|
||
this._loginServicesHandle = | ||
this.connection.subscribe("meteor.loginServiceConfiguration"); | ||
|
@@ -43,19 +43,23 @@ export class AccountsClient extends AccountsCommon { | |
// also uses it to make loggingIn() be true during the beginPasswordExchange | ||
// method call too. | ||
_setLoggingIn(x) { | ||
if (this._loggingIn !== x) { | ||
this._loggingIn = x; | ||
this._loggingInDeps.changed(); | ||
} | ||
this._loggingIn.set(x); | ||
} | ||
|
||
/** | ||
* @summary True if a login method (such as `Meteor.loginWithPassword`, `Meteor.loginWithFacebook`, or `Accounts.createUser`) is currently in progress. A reactive data source. | ||
* @locus Client | ||
*/ | ||
loggingIn() { | ||
this._loggingInDeps.depend(); | ||
return this._loggingIn; | ||
return this._loggingIn.get(); | ||
} | ||
|
||
/** | ||
* @summary True if a logout method (such as `Meteor.logout`) is currently in progress. A reactive data source. | ||
* @locus Client | ||
*/ | ||
loggingOut() { | ||
return this._loggingOut.get(); | ||
} | ||
|
||
/** | ||
|
@@ -65,9 +69,11 @@ export class AccountsClient extends AccountsCommon { | |
*/ | ||
logout(callback) { | ||
var self = this; | ||
self._loggingOut.set(true); | ||
self.connection.apply('logout', [], { | ||
wait: true | ||
}, function (error, result) { | ||
self._loggingOut.set(false); | ||
if (error) { | ||
callback && callback(error); | ||
} else { | ||
|
@@ -138,6 +144,15 @@ Meteor.loggingIn = function () { | |
return Accounts.loggingIn(); | ||
}; | ||
|
||
/** | ||
* @summary True if a logout method (such as `Meteor.logout`) is currently in progress. A reactive data source. | ||
* @locus Client | ||
* @importFromPackage meteor | ||
*/ | ||
Meteor.loggingOut = function () { | ||
return Accounts.loggingOut(); | ||
}; | ||
|
||
/// | ||
/// LOGIN METHODS | ||
/// | ||
|
@@ -438,4 +453,24 @@ if (Package.blaze) { | |
Package.blaze.Blaze.Template.registerHelper('loggingIn', function () { | ||
return Meteor.loggingIn(); | ||
}); | ||
|
||
/** | ||
* @global | ||
* @name loggingOut | ||
* @isHelper true | ||
* @summary Calls [Meteor.loggingOut()](#meteor_loggingout). | ||
*/ | ||
Package.blaze.Blaze.Template.registerHelper('loggingOut', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize there is already code in this file that assumes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good - I'll get this resolved - thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just reviewing this now - it looks like there is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
return Meteor.loggingOut(); | ||
}); | ||
|
||
/** | ||
* @global | ||
* @name loggingInOrOut | ||
* @isHelper true | ||
* @summary Calls [Meteor.loggingIn()](#meteor_loggingin) or [Meteor.loggingOut()](#meteor_loggingout). | ||
*/ | ||
Package.blaze.Blaze.Template.registerHelper('loggingInOrOut', function () { | ||
return (Meteor.loggingIn() || Meteor.loggingOut()); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const username = 'jsmith'; | ||
const password = 'password'; | ||
|
||
const logoutAndCreateUser = (test, done, nextTests) => { | ||
Meteor.logout(() => { | ||
// Make sure we're logged out to start with | ||
test.isFalse(Meteor.user()); | ||
|
||
// Setup a new test user | ||
Accounts.createUser({ username, password }, () => { | ||
// Handle next tests | ||
nextTests(test, done); | ||
}); | ||
}); | ||
}; | ||
|
||
const removeTestUser = (done) => { | ||
Meteor.call('removeAccountsTestUser', username, () => { | ||
done(); | ||
}); | ||
}; | ||
|
||
Tinytest.addAsync( | ||
'accounts - Meteor.loggingIn() is true right after a login call', | ||
(test, done) => { | ||
logoutAndCreateUser(test, done, () => { | ||
// Login then immediately verify loggingIn is true | ||
Meteor.loginWithPassword(username, password); | ||
test.isTrue(Meteor.loggingIn()); | ||
removeTestUser(done); | ||
}); | ||
} | ||
); | ||
|
||
Tinytest.addAsync( | ||
'accounts - Meteor.loggingIn() is false after login has completed', | ||
(test, done) => { | ||
logoutAndCreateUser(test, done, () => { | ||
// Login then verify loggingIn is false after login has completed | ||
Meteor.loginWithPassword(username, password, () => { | ||
test.isTrue(Meteor.user()); | ||
test.isFalse(Meteor.loggingIn()); | ||
removeTestUser(done); | ||
}); | ||
}); | ||
} | ||
); | ||
|
||
Tinytest.addAsync( | ||
'accounts - Meteor.loggingOut() is true right after a logout call', | ||
(test, done) => { | ||
logoutAndCreateUser(test, done, () => { | ||
// Logout then immediately verify loggingOut is true | ||
Meteor.logout(); | ||
test.isTrue(Meteor.loggingOut()); | ||
removeTestUser(done); | ||
}); | ||
} | ||
); | ||
|
||
Tinytest.addAsync( | ||
'accounts - Meteor.loggingOut() is false after logout has completed', | ||
(test, done) => { | ||
logoutAndCreateUser(test, done, () => { | ||
// Logout then verify loggingOut is false after logout has completed | ||
Meteor.logout((error) => { | ||
test.isFalse(Meteor.user()); | ||
test.isFalse(Meteor.loggingOut()); | ||
removeTestUser(done); | ||
}); | ||
}); | ||
} | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Meteor.methods({ | ||
removeAccountsTestUser(username) { | ||
Meteor.users.remove({ username }); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import "./accounts_url_tests.js"; | ||
import "./accounts_reconnect_tests.js"; | ||
import "./accounts_client_tests.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use
ReactiveVar
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback @raix! I didn't use a
ReactiveVar
since these changes were modelled after the existingloggingIn
code. That being said, using aReactiveVar
would definitely clean the code up a bit. I'll look into making these changes, and consider updating the code forloggingIn
as well (and add some new tests for that part of the code since there don't seem to be any). Thanks again for taking a look at this!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point