Created
July 13, 2020 13:19
-
-
Save deeja/0af182c789449a9074166e8acc5c325b to your computer and use it in GitHub Desktop.
Nuxt Firebase "@nuxtjs/firebase" plug in alternative for vuex that returns the JWT token and sets in Vuex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using the "@nuxtjs/firebase" module | |
import {mutationNames} from '@/data/StoreNames' | |
export default async ({ store, app }, inject) => { | |
// Sets up a listener, mutations and action for every onAuthStateChanged by Firebase. | |
// AND runs the functions once BEFORE the root Vue.js Application is instantiated. | |
const unsubscribe = await new Promise(resolve => { | |
const unsubscribe = app.$fireAuth.onAuthStateChanged(async user => { | |
const credential = user ? (await user.getIdTokenResult(true)) : null | |
store.commit(mutationNames.ON_AUTH_STATE_CHANGED_MUTATION, { user, credential }) | |
resolve(unsubscribe) | |
}) | |
}) | |
inject('fireAuthUnsubscribe', unsubscribe) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment