Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion src/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ export async function getDownloadURL(file: File): Promise<string> {
const endpoint =
(process.env.STORAGE_EMULATOR_HOST ||
'https://firebasestorage.googleapis.com') + '/v0';
const { downloadTokens } = await getFirebaseMetadata(endpoint, file);
const headers = process.env.STORAGE_EMULATOR_HOST
? { Authorization: 'Bearer owner' }

Choose a reason for hiding this comment

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

medium

The string 'Bearer owner' is a special value used to bypass security rules in the Firebase emulator. Adding a brief comment here would improve code clarity for future maintainers who might not be familiar with this emulator-specific behavior.

Suggested change
? { Authorization: 'Bearer owner' }
? { Authorization: 'Bearer owner' } // Bypass emulator security rules

: undefined;
const { downloadTokens } = await getFirebaseMetadata(
endpoint,
file,
headers
);
if (!downloadTokens) {
throw new FirebaseError({
code: 'storage/no-download-token',
Expand Down
4 changes: 3 additions & 1 deletion src/storage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export interface FirebaseMetadata {

export function getFirebaseMetadata(
endpoint: string,
file: File
file: File,
headers?: { [key: string]: string }
): Promise<FirebaseMetadata> {
const uri = `${endpoint}/b/${file.bucket.name}/o/${encodeURIComponent(
file.name
Expand All @@ -30,6 +31,7 @@ export function getFirebaseMetadata(
{
method: 'GET',
uri,
headers,
},
(err, body) => {
if (err) {
Expand Down