Fix deleting own account

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-08-23 10:20:31 +02:00
parent 89da83dce4
commit c2b72b45d3
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -180,14 +180,29 @@
}} }}
</p> </p>
<form @submit.prevent="deleteAccount"> <form @submit.prevent="deleteAccount">
<b-field v-if="hasUserGotAPassword"> <b-field
:type="deleteAccountPasswordFieldType"
v-if="hasUserGotAPassword"
label-for="account-deletion-password"
>
<b-input <b-input
type="password" type="password"
v-model="passwordForAccountDeletion" v-model="passwordForAccountDeletion"
password-reveal password-reveal
id="account-deletion-password"
:aria-label="$t('Password')"
icon="lock" icon="lock"
:placeholder="$t('Password')" :placeholder="$t('Password')"
/> />
<template #message>
<b-message
type="is-danger"
v-for="message in deletePasswordErrors"
:key="message"
>
{{ message }}
</b-message>
</template>
</b-field> </b-field>
<b-button <b-button
native-type="submit" native-type="submit"
@ -217,6 +232,7 @@
<script lang="ts"> <script lang="ts">
import { IAuthProvider } from "@/types/enums"; import { IAuthProvider } from "@/types/enums";
import { GraphQLError } from "graphql/error/GraphQLError";
import { Component, Vue, Ref } from "vue-property-decorator"; import { Component, Vue, Ref } from "vue-property-decorator";
import { Route } from "vue-router"; import { Route } from "vue-router";
import { import {
@ -256,6 +272,8 @@ export default class AccountSettings extends Vue {
changePasswordErrors: string[] = []; changePasswordErrors: string[] = [];
deletePasswordErrors: string[] = [];
isDeleteAccountModalActive = false; isDeleteAccountModalActive = false;
passwordForAccountDeletion = ""; passwordForAccountDeletion = "";
@ -313,6 +331,8 @@ export default class AccountSettings extends Vue {
async deleteAccount(): Promise<Route | void> { async deleteAccount(): Promise<Route | void> {
try { try {
this.deletePasswordErrors = [];
console.debug("Asking to delete account...");
await this.$apollo.mutate({ await this.$apollo.mutate({
mutation: DELETE_ACCOUNT, mutation: DELETE_ACCOUNT,
variables: { variables: {
@ -321,7 +341,8 @@ export default class AccountSettings extends Vue {
: null, : null,
}, },
}); });
await logout(this.$apollo.provider.defaultClient); console.debug("Deleted account, logging out client...");
await logout(this.$apollo.provider.defaultClient, false);
this.$buefy.notification.open({ this.$buefy.notification.open({
message: this.$t( message: this.$t(
"Your account has been successfully deleted" "Your account has been successfully deleted"
@ -333,7 +354,9 @@ export default class AccountSettings extends Vue {
return await this.$router.push({ name: RouteName.HOME }); return await this.$router.push({ name: RouteName.HOME });
} catch (err) { } catch (err) {
return this.handleErrors("delete", err); this.deletePasswordErrors = err.graphQLErrors.map(
({ message }: GraphQLError) => message
);
} }
} }
@ -361,6 +384,10 @@ export default class AccountSettings extends Vue {
); );
} }
get deleteAccountPasswordFieldType(): string | null {
return this.deletePasswordErrors.length > 0 ? "is-danger" : null;
}
private handleErrors(type: string, err: any) { private handleErrors(type: string, err: any) {
console.error(err); console.error(err);