Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(rtdb): Apply fake credentials when getting rules for rtdb emulator#3028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
amalej wants to merge2 commits intofirebase:main
base:main
Choose a base branch
Loading
fromamalej:amalej_fix-rtdb-getrules-emulator
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletionssrc/database/database.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,7 +196,7 @@ const RULES_URL_PATH = '.settings/rules.json';
class DatabaseRulesClient {

private readonly dbUrl: string;
private readonly httpClient:AuthorizedHttpClient;
private readonly httpClient:DatabaseRulesHttpClient;

constructor(app: App, dbUrl: string) {
let parsedUrl = new URL(dbUrl);
Expand All@@ -208,7 +208,7 @@ class DatabaseRulesClient {

parsedUrl.pathname = path.join(parsedUrl.pathname, RULES_URL_PATH);
this.dbUrl = parsedUrl.toString();
this.httpClient = newAuthorizedHttpClient(app as FirebaseApp);
this.httpClient = newDatabaseRulesHttpClient(app as FirebaseApp);
}

/**
Expand DownExpand Up@@ -316,6 +316,16 @@ class DatabaseRulesClient {
}
}

class DatabaseRulesHttpClient extends AuthorizedHttpClient {
protected getToken(): Promise<string> {
const emulatorHost = process.env.FIREBASE_DATABASE_EMULATOR_HOST;
if (emulatorHost) {
return Promise.resolve('owner');
}
return super.getToken();
}
}
Comment on lines +319 to +327

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

medium

To improve readability and maintainability, it's a good practice to avoid magic strings. Consider defining'owner' as a private static constant within the class.

classDatabaseRulesHttpClientextendsAuthorizedHttpClient{privatestaticreadonlyEMULATOR_AUTH_TOKEN='owner';protectedgetToken():Promise<string>{constemulatorHost=process.env.FIREBASE_DATABASE_EMULATOR_HOST;if(emulatorHost){returnPromise.resolve(DatabaseRulesHttpClient.EMULATOR_AUTH_TOKEN);}returnsuper.getToken();}}


function extractNamespace(parsedUrl: URL): string {
const ns = parsedUrl.searchParams.get('ns');
if (ns) {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp