Using Vue.js to Authenticate Users with JWT Tokens Sent in Registration Emails

Hey everyone, I could really use some assistance with JWT tokens. I created a registration form using Vue.js and sent the data to the database using axios. Now, I need help figuring out how to save the token I receive in the confirmation email so that I can send the STATE and TOKEN to the validateRegister API to complete the registration process. This is all new to me as it's my first time working with Vue and axios.

import axios from 'axios'

export default {
    name: 'Register',
    data() {
        return {
            email: '',
            password: '',
            name: '',
            surname: '',
            data: '',
            telefono: '',
            risiedi: '',
            cap: '',
            provincia: '',
            citta: '',
            privacy: false
        }
    },
    methods: {
        async handleSubmit() {
            const response = await axios.post('api/users/register',{
                email: this.email,
                password: this.password,
                name: this.name,
                surname: this.surname,
            });
            console.log(response);
        }
    }
}

Here's the link that was included in the email https://i.sstatic.net/a7ohK.png

Answer №1

Hey there, to make a request using axios, you'll need to add a header like this:

const headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer fefege...'
}

//Data
const data = {...}

const response = await axios.post('api/users/register', data, {
    headers: headers
})...

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

Error message: Unable to access property in VueJS due to TypeError

Hey there, I'm diving back into Vue after a couple of years and need a quick refresher. I know it's a simple question, but I can't seem to figure out what I'm doing wrong. I have a basic counter example where I'm trying to incremen ...

When the AJAX function is called again, the previous loading process is interrupted, without the use of jQuery

I have created a function that loads a URL into an element, but it seems to be encountering issues when called repeatedly in a loop to load multiple elements. The current load operation stops prematurely: function loadDataFromURL(url, elementId) { var ...

What is the best way to keep track of the number of checked checkboxes and add them to a separate div?

I need to select multiple checkboxes from different sections, count them, and then append the same number of sections to another div. ...

Is there a way to eliminate the surplus 2 download icons from this Angular code when there are a total of 3 users?

Here is some HTML code snippet: <tr *ngFor="let user of users"> <td> <h6 class="font-medium">{{user.id}}</h6> </td> <td> <h ...

Calculate the sum in real-time using JavaScript

How can I dynamically compute the sum of subtotals without encountering the following error? document.getElementById("item_subtotal[" + cnt + "]") is null Below is my JavaScript code: function calculateTotalAll(numitems) { var cnt = 1; var tot ...

Can a JavaScript function spontaneously run without being called upon?

<a onclick="determineCountry(data)" class="installbtn">Install</a> My goal is to have the user redirected to one of three sites based on their location when they click the button above. However, there seems to be an issue with the script below ...

Unsuccessful attempts to animate with Jquery in Google Chrome are persisting

I've been facing a challenge with my jquery code that seems to be getting the "click" function but does not animate. Instead, it just abruptly jumps without any smooth animation. I've spent hours trying to troubleshoot this issue. Here is the Jq ...

What are the steps to creating a custom CSS rule?

While it may seem unconventional, I can't help but wonder if it's possible to create a custom CSS rule using jQuery. Imagine being able to specify something like this in a CSS stylesheet: div { color: white; background: red; /*declaring m ...

What techniques does Angular2 use to handle dependency injection?

When working with Angular2 components, I know that to inject a dependency, you simply annotate an argument in the constructor, like how ThingService is injected here. However, what I am wondering is how Angular actually knows what to inject at runtime. A ...

Personalizing a Doughnut Graph

Currently in the process of creating a donut chart I am looking to achieve a design similar to the image below, where the values are displayed within the colored segments import DonutChart from 'react-d3-donut'; let data = [{ count ...

Tips on inserting a script prior to the body tag

It appears to be a straightforward process, but I am struggling to figure out what I am missing: var string1 = document.createElement('script'); $(string1).attr('type', 'text/javascript'); $('body').before($(string ...

Creating a decorative ribbon in three.js for your gift presentation

How can I create a ribbon for a gift box using three.js, similar to the example shown here: Is it possible to create the ribbon with just one piece or do I need multiple pieces to achieve the desired look? Thank you :) ...

Implementing VueJS 3 component loading in Laravel 9

I am currently working on creating a component using Laravel 9 and VueJS 3. The component includes a datatable, and I am utilizing vue-good-table-next for this purpose. However, I am encountering an issue trying to display it in my blade template and I&apo ...

The drop-down menu is failing to display the correct values in the second drop-down

Having trouble with the update feature in this code. There are 2 textboxes and 2 dropdowns, but when selecting a course code, the corresponding values for the subject are not being posted. Can anyone assist? view:subject_detail_view <script type="te ...

The scrollbar will be visible only when the mouse hovers over the table

I have been experimenting with customizing the scrollbar appearance of an ant design table. Currently, the scrollbar always displays as shown in this demo: https://i.stack.imgur.com/vlEPB.png However, I am trying to achieve a scroll behavior where the sc ...

When the mouse is moved, display a rectangle on the canvas

I am having an issue with drawing a rectangle on canvas. The code below works fine, except that the path of the rectangle is not visible while the mouse is moving. It only appears when I release the mouse button. Any assistance would be greatly appreciate ...

Show labels for data on a circular graph using angular-chart.js

I recently created a pie chart using angular-chart.js and it's functioning smoothly. However, I'm facing an issue with displaying the data value on each section of the pie chart. My attempt to use Chart.PieceLabel.js by adding the code snippet b ...

Passing the title of a page as data to a component in Next.js

I am currently working on setting a custom title for each page within my next.js project. Here is an example of a simple Layout: const MainLayout = props => { return ( <Layout style={{ minHeight: "100vh" }}> <Head> < ...

Guide to manipulating DOM elements with Angular.js: inserting or deleting elements using createElement

Within my Angular directive, I am dynamically generating an external script from the DOM for a specific object within a list. This script includes both a 'script' tag and div content. While I am able to successfully add the script, I am encounter ...

Generating Bootstrap Vue Dropdown components in real time

I am currently utilizing Bootstrap Vue to construct a dynamic Dropdown component that can render different elements such as item, title, and divider. Is there a method to accomplish this task effectively? The desired outcome for the Dropdown component wou ...