Skip to content
Snippets Groups Projects
Commit 541fceb8 authored by Ingrid Martinsheimen Egge's avatar Ingrid Martinsheimen Egge :cow2:
Browse files

man kan slette account

parent 52ae287e
No related branches found
No related tags found
1 merge request!21Merge profilinnstillinger into main
Pipeline #221431 failed
......@@ -95,8 +95,16 @@ export default {
alert("Du må bekrefte at du vil slette konto ved å huke av boksen")
}
else {
alert("(Denne knappen gjør ingen ting) men account deleted")
API.deleteAccount(this.user.id, token);
const id = this.user.id;
API.deleteAccount(
id
).then((savedUser)=>{
useAuthStore().setUser(savedUser);
alert("Bruker oppdatert.")
}).catch((error)=> {
alert("Det oppsto en feil ved sletting av bruker")
console.log(error)
})
}
},
}
......
......@@ -110,15 +110,21 @@ export const API = {
* @param token
* @returns {Promise<*>}
*/
deleteAccount: async (id, token) => {
return axios.delete(`${import.meta.env.VITE_BACKEND_URL}/account/{id}`, {
headers: { Authorization: `Bearer ${token}` },
deleteAccount: async (id) => {
const authStore = useAuthStore();
if (!authStore.isLoggedIn) {
throw new Error();
}
return axios.delete(`${import.meta.env.VITE_BACKEND_URL}/account/${id}`, {
headers: { Authorization: `Bearer ${authStore.token}` },
})
.then((response) => {
return response.data;
.then(() => {
authStore.logout()
router.push('/login')
})
.catch(() => {
throw new Error("Account not found or not accessible");
throw new Error("");
});
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment