Skip to content

Commit

Permalink
refactoring code - profile update
Browse files Browse the repository at this point in the history
  • Loading branch information
João Victor Carvalho committed Dec 12, 2022
1 parent acafcca commit bd6c24c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 5 additions & 1 deletion frontend/src/stores/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ export const useUserStore = defineStore('User', () => {

async function put(user) {
try {
const { data, status } = await api.put(`/users/${Cookies.get('idUser')}`, user)
const { data, status } = await api.put(`/users/${Cookies.get('idUser')}`, user, {
headers: {
Authorization: `Bearer ${Cookies.get('token')}`
}
})
const response = data.data
if (status == 200) return response
} catch (error) {
Expand Down
26 changes: 24 additions & 2 deletions frontend/src/views/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ const city = ref('')
const email = ref('')
const password = ref('')
const User = {
email: String,
password: String,
username: String,
city: String,
phone: String
}
const user = ref(User)
function handleName(s) { name.value = s }
function handlePhone(s) { phone.value = s }
function handleCity(s) { city.value = s }
Expand All @@ -31,8 +41,20 @@ async function updateUser() {
if(phone.value.length > 0) user.value.phone = phone.value
if(city.value.length > 0) user.value.city = city.value
if(password.value.length > 0) user.value.password = password.value
let idUser = route.fullPath.split("/profile/")
const result = await userStore.put(idUser[1])
console.log({
name: name.value,
phone: phone.value,
city: city.value,
email: email.value,
password: password.value
})
const result = await userStore.put({
name: name.value,
phone: phone.value,
city: city.value,
email: email.value,
password: password.value
})
if (result) {
validationMessage.value = ""
let redirect = `/profile/${idUser[1]}`
Expand Down

0 comments on commit bd6c24c

Please sign in to comment.