Vue3 Composition Api for Firebase (Vite)

Vue Firebase Composition Api

Powered by Vite

Also checkout a fork Firebase Composition for Nuxt

Usage

<template>
  <div>UID: {{ uid }}</div>
  <pre>{{ accounts }}</pre>
  <button @click="signInWithGoogle">Sign In with Google</button>
  <button @click="createAccount({ name: 'Join' })">Add</button>
</template>

<script>
  import { initFirebase, useAuth, useCollection, useDoc } from 'vca-firebase'
  import firebaseConfig from './firebase.config.js'

  export default {
    setup() {
      initFirebase(firebase, firebaseConfig)

      const { uid, signInWithGoogle } = useAuth()
      const { docs: accounts } = useCollection('accounts')
      const { create: createAccount } = useDoc('accounts')

      return {
        signInWithGoogle,
        uid,
        accounts,
        createAccount,
      }
    },
  }
</script>

Setup

yarn create vite-app test-vca-firebase
cd test-vca-firebase
yarn add firebase
yarn add vca-firebase

Create firebase.config.js:

  • Generate config object in Firebase Console.
  • Enable/disable plugins, i.e. analytics.
export default {
  config: {
    apiKey,
    authDomain,
    databaseURL,
    projectId,
    storageBucket,
    messagingSenderId,
    appId,
    measurementId,
  },
  analytics: false,
}

Development

Setup project and run:

yarn dev

See the power of Vite! Project is available in less than 1 second!

Download Details:

Author: razbakov

Source Code: https://github.com/razbakov/vca-firebase

#vue #vuejs #javascript

Vue3 Composition Api for Firebase (Vite)
14.20 GEEK