Skip to content

Commit

Permalink
fix: remove accidental double / from firebase paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeistrich committed Jun 17, 2024
1 parent 7ccd559 commit e5e8d33
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/sync-plugins/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export function configureSyncedFirebase(config: SyncedFirebaseConfiguration) {
}
}

function joinPaths(str1: string, str2: string) {
return str2 ? [str1, str2].join('/').replace(/\/\//g, '/') : str1;
}

interface FirebaseFns {
isInitialized: () => boolean;
getCurrentUser: () => string | undefined;
Expand Down Expand Up @@ -288,7 +292,7 @@ export function syncedFirebase<TRemote extends object, TLocal = TRemote, TAs ext
} else {
saving$[id].set(true);

const path = refPath(fns.getCurrentUser()) + (fieldId ? '/' + id : '');
const path = joinPaths(refPath(fns.getCurrentUser()), fieldId ? id : '');
await fns.update(fns.ref(path), input);

saving$[id].set(false);
Expand Down Expand Up @@ -335,8 +339,10 @@ export function syncedFirebase<TRemote extends object, TLocal = TRemote, TAs ext
const deleteFn = readonly
? undefined
: (input: TRemote) => {
const path =
refPath(fns.getCurrentUser()) + (fieldId && asType !== 'value' ? '/' + (input as any)[fieldId] : '');
const path = joinPaths(
refPath(fns.getCurrentUser()),
fieldId && asType !== 'value' ? (input as any)[fieldId] : '',
);
return fns.remove(fns.ref(path));
};

Expand Down

0 comments on commit e5e8d33

Please sign in to comment.