auth.js 568 B

123456789101112131415161718192021222324252627
  1. let callbacks = [];
  2. export default {
  3. ready: false,
  4. authenticated: false,
  5. username: '',
  6. userId: '',
  7. role: 'default',
  8. getStatus: function (cb) {
  9. if (this.ready) cb(this.authenticated, this.role, this.username, this.userId);
  10. else callbacks.push(cb);
  11. },
  12. data: function (authenticated, role, username, userId) {
  13. this.authenticated = authenticated;
  14. this.role = role;
  15. this.username = username;
  16. this.userId = userId;
  17. this.ready = true;
  18. callbacks.forEach(callback => {
  19. callback(authenticated, role, username, userId);
  20. });
  21. callbacks = [];
  22. }
  23. }