felvieira
12/12/2019 - 5:14 AM

Salvar do local storage no firebase um Json

Entrar no console do firebase e criar uma colecao no database, no caso aqui foi criada a cards.

https://console.firebase.google.com/ https://www.youtube.com/watch?v=zpQle4SBRfg https://www.youtube.com/watch?v=kmTECF0JZyQ

 import { db } from "../plugins/firebaseConfig";
 
 uploadData() {
      let cards = this.storage.get("cards");
      const { email, user } = this.user;
      
      if (cards) {
        let uniqueCards = [];
        db.collection("cards")
          .get()
          .then(snapshot => {
            let cardNumbersDB = [];
            snapshot.docs.forEach(db => {
              if (db.data().cardNumber) {
                cardNumbersDB.push(db.data().cardNumber);
              }
            });
            if (cardNumbersDB.length >= 1) {
              uniqueCards = cards.filter(
                item => !cardNumbersDB.includes(item.cardNumber)
              );
              uniqueCards.forEach(card => {
                db.collection("cards").add({
                  cardCVC: card.cardCVC,
                  cardExpiration: card.cardExpiration,
                  cardName: card.cardName,
                  cardNumber: card.cardNumber,
                  cardSelectedFlag: card.cardSelectedFlag,
                  cardTitle: card.cardTitle,
                  email: email,
                  name: name
                });
              });
            } else {
              cards.forEach(card => {
                db.collection("cards").add({
                  cardCVC: card.cardCVC,
                  cardExpiration: card.cardExpiration,
                  cardName: card.cardName,
                  cardNumber: card.cardNumber,
                  cardSelectedFlag: card.cardSelectedFlag,
                  cardTitle: card.cardTitle,
                  email: email,
                  name: name
                });
              });
            }
          });
      }
    },
import * as firebase from "firebase";
import "firebase/firestore";

const config = {
  apiKey: "AIzaSyCENjKCZGXfeEhTb8Q5fO3bLqX_mxckMhQ",
  authDomain: "carteira-facil.firebaseapp.com",
  databaseURL: "https://carteira-facil.firebaseio.com",
  projectId: "carteira-facil",
  storageBucket: "carteira-facil.appspot.com",
  messagingSenderId: "462064693933"
};

const fireApp = firebase.initializeApp(config);

export const AUTH = fireApp.auth();
export const db = firebase.firestore();
{
  "name": "carteira-facil",
  "version": "1.7.2",
  "description": "App para organizar cartões e documentos",
  "productName": "Carteira Fácil",
  "cordovaId": "cordova.carteirafacil.app",
  "author": "Felipe Vieira <flpchapola@hotmail.com>",
  "private": true,
  "scripts": {
    "dev": "quasar dev",
    "lint": "eslint --ext .js,.vue src",
    "test": "echo \"No test specified\" && exit 0"
  },
  "dependencies": {
    "axios": "^0.18.1",
    "core-js": "^2.6.5",
    "file-saver": "^1.3.8",
    "firebase": "^6.6.2",
    "firebaseui": "^3.6.1",
    "mobile-detect": "^1.4.4",
    "moment": "^2.24.0",
    "vue-the-mask": "^0.11.1"
  },
  "devDependencies": {
    "babel-eslint": "^8.2.6",
    "copy-webpack-plugin": "^4.6.0",
    "eslint": "^4.18.2",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-friendly-formatter": "^4.0.1",
    "eslint-loader": "^2.2.1",
    "eslint-plugin-import": "^2.19.1",
    "eslint-plugin-vue": "^4.7.1",
    "node-sass": "^4.13.0",
    "quasar-cli": "^0.16.0",
    "sass-loader": "^7.3.1",
    "serviceworker-webpack-plugin": "^0.2.3"
  },
  "engines": {
    "node": ">= 8.9.0",
    "npm": ">= 5.6.0",
    "yarn": ">= 1.6.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 10"
  ]
}