auth.js 502 B

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