FirebaseStub: added auth User class

This commit is contained in:
gianantoniopini
2021-05-11 16:42:36 +02:00
parent eb54a7f69d
commit e794325787
4 changed files with 80 additions and 6 deletions

View File

@ -2,6 +2,7 @@
import { v4 as uuidv4 } from 'uuid';
import Constants from '../constants/auth';
import User from './user';
import { delay } from '../../../src/utils/index';
const singleton = Symbol('');
@ -14,6 +15,7 @@ class Auth {
}
this._uuid = uuidv4();
this._currentUser = null;
this._onAuthStateChangedObservers = [];
}
@ -25,6 +27,10 @@ class Auth {
return this[singleton];
}
get currentUser() {
return this._currentUser;
}
get uuid() {
return this._uuid;
}
@ -46,11 +52,21 @@ class Auth {
async signInAnonymously() {
const user = Constants.anonymousUser1;
this._currentUser = new User(
user.displayName,
user.email,
user.isAnonymous,
user.uid,
async () => {},
);
await delay(Constants.defaultDelayInMilliseconds);
this.onAuthStateChangedObservers.forEach((observer) => observer(user));
this.onAuthStateChangedObservers.forEach((observer) =>
observer(this._currentUser),
);
return user;
return this._currentUser;
}
}