auth.js 518 B

12345678910111213141516171819202122232425262728
  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) {
  9. cb(this.authenticated, this.role, this.username);
  10. } else {
  11. callbacks.push(cb);
  12. }
  13. },
  14. data: function(authenticated, role, username) {
  15. this.authenticated = authenticated;
  16. this.role = role;
  17. this.username = username;
  18. this.ready = true;
  19. callbacks.forEach((callback) => {
  20. callback(authenticated, role, username);
  21. });
  22. callbacks = [];
  23. }
  24. }