CyCraft / magnetar

A framework-agnostic syncing solution that auto-connects any DB/API with your local data store and has optimistic-UI built in 🌟
https://magnetar.cycraft.co
MIT License
43 stars 5 forks source link

feat(docs): add complete Vue 2 and Vue 3 examples to docs #14

Open mesqueeb opened 3 years ago

mesqueeb commented 3 years ago

open questions:

OliverJEvans commented 1 year ago

I would be interested in the auth example here.

I'm finding myself doing some hybrid Pinia thing, where I sign in with firebase/auth, get the uid and store it in Pinia (I guess this could also be local storage etc). Then when I want the user doc, I use the UID in pinia to getch the users document.

This screams anti-pattern to me but I'm unsure what the intended implementation would be, my firebase experience isn't that great.

Here's kinda what I'm doing at the moment

import { mapState } from "pinia";
import { useAuthStore } from "@/stores/auth";
import { magnetar } from "@/firebase/setup.js";

export default {
  data() {
    return {
      userDoc: null,
    };
  },
  created() {
    this.userDoc = magnetar.collection("users").doc(this.user.uid);
    this.userDoc.stream().catch((error) => {
      console.log(error);
    });
  },
  beforeDestroy() {
    this.userDoc.closeStream();
  },
  computed: {
    ...mapState(useAuthStore, ["user"]),
  },
  methods: {
    handleButtonClick() {
        this.userDoc.merge({...});
    },
  },
};