Record the user actions from logging in through Facebook or OAuth and store them in the database

I have been attempting to log in with Facebook using Firebase. How can I save user information such as email and username to the database? Additionally, I am unsure of what steps to take next when users engage in activities like ordering products on my website. For instance, if they log in again via Facebook at a later time, how would I, as an admin, retrieve data from the database? (@nuxtjs/firebase) What should be my next course of action? This is something I have been researching for the past 2 months.

<template>
  <div>
    <v-row no-gutters>
      <v-col cols="12" md="12" sm="12">
        <v-card>
          <v-row no-gutters>
            <v-col cols="12" md="12" sm="12">
              <v-form @submit.prevent="loginUser">
                <v-col cols="12" md="12" sm="12">
                  <v-text-field
                    type="email"
                    error-count=""
                    placeholder=""
                    label="email"
                    append-icon="mdi-email"
                    v-model="email"
                    outlined
                    color
                  ></v-text-field>
                </v-col>
                <v-col cols="12" md="12" sm="12">
                  <v-text-field
                    type="email"
                    error-count=""
                    placeholder=""
                    label="password"
                    append-icon="mdi-password"
                    v-model="password"
                    outlined
                    color
                  ></v-text-field>
                </v-col>
                <v-col cols="12" md="12" sm="12">
                  <v-btn medium elevation="" color="primary" type="submit"
                    >login</v-btn
                  >
                </v-col>
                <v-col cols="12" md="12" sm="12">
                  <v-btn
                    medium
                    elevation=""
                    color="primary"
                    type=""
                    @click="loginWithFacebook()"
                    >log in with facebook</v-btn
                  >
                </v-col>
              </v-form>
            </v-col>
          </v-row>
        </v-card>
      </v-col>
    </v-row>
  </div>
</template>

<script>
export default {
  data: () => ({
    email: '',
    password: '',
  }),
  methods: {
    async loginUser() {
      try {
        const response = await this.$fire.auth.signInWithEmailAndPassword(
          this.email,
          this.password
        )
        console.log(response)
        this.$router.replace({ name: 'test1' })
      } catch (e) {
        console.error(e)
      }
    },
    async loginWithFacebook() {
      try {
        const provider = new this.$fireModule.auth.FacebookAuthProvider()
        let authData = await this.$fire.auth.signInWithPopup(provider)
        console.log(authData)
      } catch (e) {
        console.error(e)
      }
    },
  },
}
</script>

<style></style>

Answer №1

To troubleshoot login issues, you can verify the user's status (logged in or logged out) using the following code snippet:

this.$fire.auth.onAuthStateChanged(user => { 

  if (user) {          

    this.$store.state.user.loggedIn = true;  

    this.loggedIn = true;

  } else {

    this.loggedIn = false;    
    this.$router.push('/login');

  }

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to manipulate the selected tab material using a custom directive with two-way data binding

I've been struggling to change the tab using code and can't seem to figure out what's causing the error. It works fine when I use the controller to change the variable, but when trying to bind it through a directive, it breaks. var app = an ...

When attempting to duplicate a project from Bitbucket and working in VS Code, I encountered several errors and warnings while running npm install

I have a project on Bitbucket that I'm trying to clone. The project is quite old, about 3 years old, so some packages may be outdated. However, when I run npm install, I am seeing a lot of warnings and errors. Additionally, the project was originally ...

Vue Leaflet 2.0 utilizes ES modules in order to reduce the size of the

In my Vue-cli 2 project, I have imported Vue2-leaflet modules LMap and LTileLayer in my main.js like this: import { LMap, LTileLayer } from 'vue2-leaflet' Despite following the suggestion to only import the needed modules, the webpack-bundle-ana ...

The term 'string' is typically employed as a data type, yet in this instance it is being utilized as an actual value

Just started working with TypeScript and encountered an issue while trying to set the state. Encountered this error message: 'string' is a type and cannot be used as a value here. const state = reactive({ user: { uid: "", ...

Tips on adding a base64 encoded image string to a JSON object using JavaScript

I'm trying to convert an image file into a JSON object using JavaScript. I've managed to turn the image into a string by utilizing base64 encoding, but I'm unsure how to then convert this string into a JSON object. Can anyone help? ...

How to pass a JavaScript variable value to a SQL query in PHP on a separate webpage?

I have 2 elements - an auto search bar and Map using mapbox-gl. I want to load the location of the user whose id is searched. I am getting the same marker (location) for every user. I am loading "get_pin.php" through xmlHttpRequest from the main page "m ...

What is the jQuery equivalent for converting this JavaScript code?

Here's a code snippet that I am struggling with: data=>{document.querySelector( "#os11.html-widget.gauge svg text[font-size='10px'] tspan" ).innerHTML = data.text I attempted the following solution: $("#os11.html ...

AngularJS ng-repeat: displaying a list of filtered outcomes exclusively

I currently have a ng repeat that loops through a set of results. <a class="list-group-item" href="#trip/{{trip.id}}/overview" ng-repeat="trip in trips | filter:search | limitTo:-15"> Basically, as I enter more text into my input field, the list sh ...

VueRouter - The local storage data will be wiped out if a trailing slash is not included in the URL

Storing a JWT token in localStorage has caused an issue where the token is only visible in Developer Tools when visiting https://www.example.com/my-web-app/. However, when visiting https://www.example.com/my-web-app, the data in localStorage remains invisi ...

The issue with Gulp revRewrite module failing to properly rewrite CSS and JS files within the project

I have been utilizing Gulp v.4 from npm along with the gulp-rev and gulp-rev-rewrite plugins to prevent Cache Busting of CSS and JS files. However, despite going through numerous guides and notes, I am encountering an issue where the links inside my HTML ( ...

Do ES6 features get transpiled into ES5 when utilized in TypeScript?

After implementing ES6 features such as template strings, arrow functions, and destructuring in a TypeScript file, I compile the code to regular JavaScript... Does the TypeScript compiler also compile the ES6 syntax, or do I need to utilize another compil ...

Tips for combining arrays of objects

I have two arrays containing objects const obj = { teamRows: [ {name: 'Alice', admin_id: 1}, {name: 'Bob', admin_id: 2}, {name: 'Charlie', admin_id: 3}, ], roleRows: [ {title: &apos ...

Prevent user control postback from occurring when JavaScript is active

I have been on a mission to find a solution to this issue. Hopefully, someone in this community can shed some light on it! I developed a usercontrol that utilizes .NET web controls, but I want to enhance the user experience by avoiding full postbacks. As ...

Not receiving connections on localhost port 3000

Our team has successfully created a basic Express Node website https://i.stack.imgur.com/5fwmC.png We attempted to run the app using DEBUG=express_example:* npm start https://i.stack.imgur.com/NI5lR.png We also tried running it with node DEBUG=express_ ...

The refusal to run JavaScript stemmed from an empty MIME type, resulting from the combination of nodeJS, express, engintron, and nginx

Currently, I'm struggling with a frustrating issue that's making me want to pull my hair out. So, here's some important information you need to be aware of: My application is built using node.js (version 16.13.1) with express and nginx man ...

Obtain information through ajax using an asynchronous function

When fetching data in the first example using ajax with XMLHttpRequest, everything works smoothly. example 1 let req = new XMLHttpRequest(); req.open( "GET", "https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/global-tempe ...

Utilize CSS to showcase the full-size version of a clicked thumbnail

I am working on a web page that features three thumbnails displayed on the side. When one of these thumbnails is clicked, the full-size image should appear in the center of the page with accompanying text below it. Additionally, I have already implemented ...

From JSON to PNG in one simple step with Fabric.js

I am looking for a way to generate PNG thumbnails from saved stringified JSON data obtained from fabric.js. Currently, I store the JSON data in a database after saving it from the canvas. However, now I want to create a gallery of PNG thumbnails using thi ...

presentation banner that doesn't rely on flash technology

Looking to create a dynamic slideshow banner for my website inspired by the design on play.com. This banner will feature 5 different slides that transition automatically after a set time, while also allowing users to manually navigate using numbered button ...

a beginner's guide to utilizing the grunt target

Here is an example of my Gruntfile.js: 'use strict'; module.exports = function(grunt) { grunt.initConfig({ grunt.config.set('targ', grunt.option('target')); cachebuster: { build: { ...