Skip to content

Commit

Permalink
fix(auth): Fixed initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
lupas committed Sep 25, 2020
1 parent a6669fc commit c4b203d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/plugins/services/auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% const { service, serviceOptions, writeImportStatement, writeInjections } = options %>
<% const { service, serviceOptions, writeImportStatement } = options %>

export default async function (session, firebase, { store }, inject) {
<%= writeImportStatement(options) %>

const service = session.<%= service %>()
const authService = session.<%= service %>()

<% if (serviceOptions.persistence) { %>
// persistence should only be enabled client side
Expand All @@ -16,7 +16,7 @@ export default async function (session, firebase, { store }, inject) {
: 'LOCAL'
%>
try {
await fireAuth.setPersistence(persistence)
await authService.setPersistence(persistence)
} catch (err) {
if (err.code === 'auth/invalid-persistence-type') {
console.warn(`[@nuxtjs/firebase]: Invalid persistence type '${persistence}' provided`)
Expand All @@ -43,15 +43,15 @@ export default async function (session, firebase, { store }, inject) {
}

return new Promise(resolve => {
this.off = service.onAuthStateChanged(async authUser => {
this.off = authService.onAuthStateChanged(async authUser => {
const claims = authUser ? (await authUser.getIdTokenResult(true)).claims : null

<% if (typeof options.onAuthStateChangedMutation === 'string') { %>
store.commit(<%= serialize(options.onAuthStateChangedMutation) %>, { authUser, claims })
<% if (typeof serviceOptions.initialize.onAuthStateChangedMutation === 'string') { %>
store.commit(<%= serialize(serviceOptions.initialize.onAuthStateChangedMutation) %>, { authUser, claims })
<% } %>

<% if (typeof options.onAuthStateChangedAction === 'string') { %>
await store.dispatch(<%= serialize(options.onAuthStateChangedAction) %>, { authUser, claims })
<% if (typeof serviceOptions.initialize.onAuthStateChangedAction === 'string') { %>
await store.dispatch(<%= serialize(serviceOptions.initialize.onAuthStateChangedAction) %>, { authUser, claims })
<% } %>

resolve()
Expand All @@ -63,5 +63,5 @@ export default async function (session, firebase, { store }, inject) {
inject('fireAuthStore', fireAuthStore)
<% } %>

return service
return authService
}

0 comments on commit c4b203d

Please sign in to comment.