Fix signup cycle (signup, confirm, login)

This commit is contained in:
aldrin 2021-04-16 11:08:28 +02:00
parent 6e4c2ddabd
commit fbb4e4502e
3 changed files with 20 additions and 17 deletions

View file

@ -30,11 +30,12 @@ async function request(
init.headers.set("Accept", "application/json");
init.headers.set("Content-Type", "application/json");
const response = await fetch(`/api/${endpoint}/`, init);
const dataOrErrors = await response.json();
if (response.status === successStatus) {
return dataOrErrors;
} else {
throw new APIError(response.statusText, dataOrErrors);
if (response.status !== 204) {
if (response.status === successStatus) {
return await response.json();
} else {
throw new APIError(response.statusText, await response.json());
}
}
}

View file

@ -52,6 +52,12 @@ export default class LoginForm extends Vue {
await this.user.login();
} else {
await this.user.signup();
this.$router.push({ name: "login" });
this.$buefy.toast.open({
message:
"Eine E-Mail zur Bestätigung deiner E-Mail-Adresse wurde versendet.",
type: "is-success",
});
}
// TODO: error handling, show confirmation page
}

View file

@ -8,15 +8,7 @@
<UserTable :user="user" />
</div>
<div v-else class="column is-3-widescreen is-4-desktop is-5-tablet">
<b-notification
v-if="isConfirmation"
type="is-success"
aria-close-label="Close notification"
>
Deine E-Mail-Adresse wurde erfolgreich bestätigt. Du kannst dich nun
anmelden.
</b-notification>
<LoginForm v-else :user="user" />
<LoginForm :user="user" />
</div>
</div>
</section>
@ -30,13 +22,17 @@ import UserTable from "@/components/UserTable.vue";
@Component({ components: { UserTable, LoginForm } })
export default class Home extends Vue {
private isConfirmation = false;
private user = new User();
public async created(): Promise<void> {
if (this.$route.name === "confirm") this.isConfirmation = true;
if (this.isConfirmation) {
if (this.$route.name === "confirm") {
await User.confirm(this.$route.params.uid, this.$route.params.token);
this.$router.push({ name: "login" });
this.$buefy.toast.open({
message:
"Deine E-Mail-Adresse wurde bestätigt. Du kannst dich nun anmelden.",
type: "is-success",
});
}
}
}