mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-14 16:51:33 +10:00
Firebase Stub refactoring
This commit is contained in:
@ -6,52 +6,7 @@ import {
|
|||||||
AuthConstants,
|
AuthConstants,
|
||||||
DatabaseConstants,
|
DatabaseConstants,
|
||||||
} from './gatsby-plugin-firebase/constants';
|
} from './gatsby-plugin-firebase/constants';
|
||||||
|
import Auth from './gatsby-plugin-firebase/auth';
|
||||||
class Auth {
|
|
||||||
static #instance = undefined;
|
|
||||||
#uuid = '';
|
|
||||||
#onAuthStateChangedObservers = [];
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
if (Auth.#instance) {
|
|
||||||
return Auth.#instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
Auth.#instance = this;
|
|
||||||
|
|
||||||
this.#uuid = uuidv4();
|
|
||||||
}
|
|
||||||
|
|
||||||
get uuid() {
|
|
||||||
return this.#uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
get onAuthStateChangedObservers() {
|
|
||||||
return this.#onAuthStateChangedObservers;
|
|
||||||
}
|
|
||||||
|
|
||||||
dispose() {
|
|
||||||
this.#onAuthStateChangedObservers = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
onAuthStateChanged(observer) {
|
|
||||||
this.#onAuthStateChangedObservers.push(observer);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
this.#onAuthStateChangedObservers = this.#onAuthStateChangedObservers.filter(
|
|
||||||
(observer) => observer !== observer,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async signInAnonymously() {
|
|
||||||
const user = AuthConstants.anonymousUser1;
|
|
||||||
|
|
||||||
this.#onAuthStateChangedObservers.forEach((observer) => observer(user));
|
|
||||||
|
|
||||||
return Promise.resolve(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Database {
|
class Database {
|
||||||
static #instance = undefined;
|
static #instance = undefined;
|
||||||
|
|||||||
51
__mocks__/gatsby-plugin-firebase/auth.js
Normal file
51
__mocks__/gatsby-plugin-firebase/auth.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
|
import { AuthConstants } from './constants';
|
||||||
|
|
||||||
|
class Auth {
|
||||||
|
static #instance = undefined;
|
||||||
|
#uuid = '';
|
||||||
|
#onAuthStateChangedObservers = [];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
if (Auth.#instance) {
|
||||||
|
return Auth.#instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
Auth.#instance = this;
|
||||||
|
|
||||||
|
this.#uuid = uuidv4();
|
||||||
|
}
|
||||||
|
|
||||||
|
get uuid() {
|
||||||
|
return this.#uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
get onAuthStateChangedObservers() {
|
||||||
|
return this.#onAuthStateChangedObservers;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispose() {
|
||||||
|
this.#onAuthStateChangedObservers = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
onAuthStateChanged(observer) {
|
||||||
|
this.#onAuthStateChangedObservers.push(observer);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
this.#onAuthStateChangedObservers = this.#onAuthStateChangedObservers.filter(
|
||||||
|
(observer) => observer !== observer,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async signInAnonymously() {
|
||||||
|
const user = AuthConstants.anonymousUser1;
|
||||||
|
|
||||||
|
this.#onAuthStateChangedObservers.forEach((observer) => observer(user));
|
||||||
|
|
||||||
|
return Promise.resolve(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Auth;
|
||||||
Reference in New Issue
Block a user