auth.js 440 B

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