firebase-auth-cloudflare-workers
Version:
Zero-dependencies firebase auth library for Cloudflare Workers.
56 lines (55 loc) • 2.01 kB
JavaScript
import { BaseAuth } from './auth';
import { AuthApiClient } from './auth-api-requests';
import { WorkersKVStore } from './key-store';
export { ServiceAccountCredential } from './credential';
export { emulatorHost, useEmulator } from './emulator';
export * from './errors';
export class Auth extends BaseAuth {
static instance;
static withCredential;
constructor(projectId, keyStore, credential) {
super(projectId, keyStore, credential);
}
static getOrInitialize(projectId, keyStore, credential) {
if (!Auth.withCredential && credential !== undefined) {
Auth.withCredential = new Auth(projectId, keyStore, credential);
}
if (Auth.withCredential) {
return Auth.withCredential;
}
if (!Auth.instance) {
Auth.instance = new Auth(projectId, keyStore);
}
return Auth.instance;
}
}
export class WorkersKVStoreSingle extends WorkersKVStore {
static instance;
constructor(cacheKey, cfKVNamespace) {
super(cacheKey, cfKVNamespace);
}
static getOrInitialize(cacheKey, cfKVNamespace) {
if (!WorkersKVStoreSingle.instance) {
WorkersKVStoreSingle.instance = new Map();
}
const instance = WorkersKVStoreSingle.instance.get(cacheKey);
if (instance) {
return instance;
}
const newInstance = new WorkersKVStoreSingle(cacheKey, cfKVNamespace);
WorkersKVStoreSingle.instance.set(cacheKey, newInstance);
return newInstance;
}
}
export class AdminAuthApiClient extends AuthApiClient {
static instance;
constructor(projectId, credential, retryConfig) {
super(projectId, credential, retryConfig);
}
static getOrInitialize(projectId, credential, retryConfig) {
if (!AdminAuthApiClient.instance) {
AdminAuthApiClient.instance = new AdminAuthApiClient(projectId, credential, retryConfig);
}
return AdminAuthApiClient.instance;
}
}