Skip to content

Commit

Permalink
fix(lazy): fixed fireModule not being injected if ready() functions a…
Browse files Browse the repository at this point in the history
…re only called in V-components

re #366
  • Loading branch information
lupas committed Jan 17, 2021
1 parent 17c0868 commit 3f37365
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/plugins/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const appConfig = <%= serialize(options.config) %>

export default async (ctx, inject) => {

/****************************************
<%/****************************************
**************** LAZY MODE **************
****************************************/
****************************************/%>
<% if (options.lazy) { %>
let firebase, session
let firebaseReady = false
Expand All @@ -26,8 +26,7 @@ export default async (ctx, inject) => {
firebaseReady = true;

<% if (options.injectModule) { %>
inject('fireModule', firebase)
ctx.$fireModule = firebase
forceInject(ctx, inject, "fireModule", firebase)
<% } %>
}
return session
Expand Down Expand Up @@ -92,9 +91,9 @@ export default async (ctx, inject) => {
ctx.$fire = fire
/****************************************
<%/****************************************
************* NON-LAZY MODE *************
****************************************/
****************************************/%>
<% } else { %>
const { firebase, session } = await createApp(appConfig, ctx)
Expand Down Expand Up @@ -133,3 +132,21 @@ export default async (ctx, inject) => {
ctx.$fire = fire
<% } %>
}


<%/*************************************
************* HELPERS********************
****************************************/%>
<%/**
Custom inject function that is able to overwrite previously injected values,
which original inject doesn't allow to do.
This method is copied from https://github.com/nuxt-community/sentry-module/blob/master/lib/plugin.lazy.js#L189
which is adapted from the inject method in nuxt/vue-app/template/index.js
Fixes https://github.com/nuxt-community/firebase-module/issues/366
**/%>
function forceInject (ctx, inject, key, value) {
inject(key, value)
const injectKey = '$' + key
ctx[injectKey] = value
window.<%= globals.nuxt %>.$options[injectKey] = value
}

0 comments on commit 3f37365

Please sign in to comment.