Skip to content

Commit bc16b45

Browse files
committed
fix(firestore): call useEmulator after enablePersistence to fix "already started" issue
Call useEmulator after enablePersistence to fix "Firestore has already been started" issue re #451
1 parent 53b067b commit bc16b45

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/plugins/services/firestore.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ export default async function (session) {
1111
firestoreService.settings(<%= serialize(serviceOptions.settings) %>)
1212
<% } %>
1313

14+
<% /* Uses emulator, if emulatorPort is set. */ %>
15+
<% if (['string', 'number'].includes(typeof serviceOptions.emulatorPort)) { %>
16+
<% const emulatorHost =
17+
typeof serviceOptions.emulatorHost === 'string'
18+
? serviceOptions.emulatorHost
19+
: 'localhost'
20+
%>
21+
// If statement fixes Issue #390, only runs useEmulator when not yet called (relevant on server)
22+
if (process.client || firestoreService._delegate._settings.host === 'firestore.googleapis.com') {
23+
firestoreService.useEmulator('<%= `${emulatorHost}` %>', <%= `${serviceOptions.emulatorPort}` %>)
24+
}
25+
<% } %>
26+
1427
<% if (serviceOptions.enablePersistence) { %>
1528
// persistence should only be enabled client side
1629
if (process.client) {
@@ -27,18 +40,5 @@ export default async function (session) {
2740
}
2841
<% } %>
2942

30-
<% /* Uses emulator, if emulatorPort is set. */ %>
31-
<% if (['string', 'number'].includes(typeof serviceOptions.emulatorPort)) { %>
32-
<% const emulatorHost =
33-
typeof serviceOptions.emulatorHost === 'string'
34-
? serviceOptions.emulatorHost
35-
: 'localhost'
36-
%>
37-
// If statement fixes Issue #390, only runs useEmulator when not yet called (relevant on server)
38-
if (process.client || firestoreService._delegate._settings.host === 'firestore.googleapis.com') {
39-
firestoreService.useEmulator('<%= `${emulatorHost}` %>', <%= `${serviceOptions.emulatorPort}` %>)
40-
}
41-
<% } %>
42-
4343
return firestoreService
4444
}

0 commit comments

Comments
 (0)