Skip to content

Commit

Permalink
fix(firestore): call useEmulator after enablePersistence to fix "alre…
Browse files Browse the repository at this point in the history
…ady started" issue

Call useEmulator after enablePersistence to fix "Firestore has already been started" issue

re #451
  • Loading branch information
lupas committed Feb 18, 2021
1 parent 53b067b commit bc16b45
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/plugins/services/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ export default async function (session) {
firestoreService.settings(<%= serialize(serviceOptions.settings) %>)
<% } %>

<% /* Uses emulator, if emulatorPort is set. */ %>
<% if (['string', 'number'].includes(typeof serviceOptions.emulatorPort)) { %>
<% const emulatorHost =
typeof serviceOptions.emulatorHost === 'string'
? serviceOptions.emulatorHost
: 'localhost'
%>
// If statement fixes Issue #390, only runs useEmulator when not yet called (relevant on server)
if (process.client || firestoreService._delegate._settings.host === 'firestore.googleapis.com') {
firestoreService.useEmulator('<%= `${emulatorHost}` %>', <%= `${serviceOptions.emulatorPort}` %>)
}
<% } %>

<% if (serviceOptions.enablePersistence) { %>
// persistence should only be enabled client side
if (process.client) {
Expand All @@ -27,18 +40,5 @@ export default async function (session) {
}
<% } %>

<% /* Uses emulator, if emulatorPort is set. */ %>
<% if (['string', 'number'].includes(typeof serviceOptions.emulatorPort)) { %>
<% const emulatorHost =
typeof serviceOptions.emulatorHost === 'string'
? serviceOptions.emulatorHost
: 'localhost'
%>
// If statement fixes Issue #390, only runs useEmulator when not yet called (relevant on server)
if (process.client || firestoreService._delegate._settings.host === 'firestore.googleapis.com') {
firestoreService.useEmulator('<%= `${emulatorHost}` %>', <%= `${serviceOptions.emulatorPort}` %>)
}
<% } %>

return firestoreService
}

0 comments on commit bc16b45

Please sign in to comment.