'Vuejs, JTW Token From Registration Email

Hi guys i need help with JTW token. i do registration form with vuejs and i send data to database with axios. I need to save the token I receive on the confirmation email and send the STATE and TOKEN on the validateRegister API to complete the registration. I'm very awkward it's the first time I use 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);
        }
    }
}

This is the link i receive on the email enter image description here



Solution 1:[1]

Olá, você precisará adicionar um header a requisição do axios, dessa forma:

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

//Dados
const data = {...}

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Victor Dornelas