i want to create a post end send to api but i need to retrive userId to create my post.
( frontend : vuejs3 + axios backend : node + prisma + sql)
Test on postman is ok but i cannot retrive usedId in vue js. can you help me please ?
import axios from "axios"
export default {
name: 'PostCreate',
data () {
return {
title: '',
content: '',
}
},
methods: {
async createPost(req) {
const token = Authorization.split(' ')[1];
// dechiffre le token a l'aide de la clé secrete et du token presant dans authorization
const decodedToken = jwt.verify(token, `${process.env.MY_TOKEN}`);
console.log('decodedToken');
const response = await axios.post('http://localhost:3000/api/post', {
headers: {
Authorization: 'Bearer ' + localStorage.getItem('token')
},
title: this.title,
content: this.content,
userId: decodedToken.userId
});
}
}
}