Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit 8e73a27

Browse files
✨ Update register UI
1 parent 1ab4607 commit 8e73a27

File tree

3 files changed

+62
-102
lines changed

3 files changed

+62
-102
lines changed

components/LargeMessage.vue

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<template>
22
<div>
3-
<img alt="" :src="`/images/${img}`" />
3+
<img alt :src="`/images/${img}`" />
44
<h1>{{ heading }}</h1>
55
<p>{{ text }}</p>
6-
<nuxt-link
7-
v-if="ctaText && ctaTo"
8-
class="button button--size-large button--color-primary section section--mt-1"
9-
:to="ctaTo"
6+
<nuxt-link v-if="ctaText && ctaTo" class="button" :to="ctaTo"
107
>{{ ctaText }} &rarr;</nuxt-link
118
>
129
</div>

pages/auth/register.vue

+59-94
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,96 @@
11
<template>
2-
<main
3-
class="container container--size-small container--top-20height container--bottom-20height"
4-
>
2+
<main class="container" style="max-width: 500px; margin: 10vh auto;">
53
<LargeMessage
6-
v-if="completedRegistration"
4+
v-if="completed"
75
heading="Check your email"
86
img="undraw_message_sent_1030.svg"
97
text="We've sent you a special link to complete your registration and activate your account."
108
/>
11-
<Card v-else>
12-
<h1>Register</h1>
13-
<Loading v-if="isLoading" message="Creating your account" />
14-
<form v-else v-meta-ctrl-enter="register" @submit.prevent="register">
15-
<Input
16-
v-model="name"
17-
type="text"
18-
label="Name"
19-
placeholder="Enter your full name"
20-
autocomplete="name"
21-
required
22-
autofocus
23-
/>
24-
<Input
25-
v-model="email"
26-
type="email"
27-
label="Email"
28-
placeholder="Enter your work email"
29-
autocomplete="email"
30-
required
31-
/>
32-
<Input
33-
v-model="password"
34-
type="password"
35-
label="Password"
36-
placeholder="Enter a secure password"
37-
autocomplete="new-password"
38-
/>
39-
<Input
40-
v-if="showInviteCode"
41-
v-model="invitedByUser"
42-
type="text"
43-
label="Invitation code"
44-
placeholder="Enter an optional invite code"
45-
help="If you have an invite code, enter that here"
46-
/>
47-
<button
48-
class="button button--width-full button--size-large"
49-
type="submit"
9+
<div v-else class="card">
10+
<form
11+
v-meta-ctrl-enter="login"
12+
class="card-content"
13+
@submit.prevent="login"
14+
>
15+
<b-field label="Name">
16+
<b-input v-model="name" type="text" required />
17+
</b-field>
18+
<b-field label="Email">
19+
<b-input v-model="email" type="email" required />
20+
</b-field>
21+
<b-field label="Password">
22+
<b-input
23+
v-model="password"
24+
type="password"
25+
required
26+
password-reveal
27+
/>
28+
</b-field>
29+
<div class="field">
30+
<b-checkbox v-model="hasInviteCode"
31+
>I have an invitation code</b-checkbox
32+
>
33+
</div>
34+
<b-field v-if="hasInviteCode" label="Invitation code">
35+
<b-input v-model="invitedByUser" type="text" />
36+
</b-field>
37+
<b-button type="is-primary" :loading="isLoading" native-type="submit"
38+
>Login to your account</b-button
5039
>
51-
Register for an account
52-
</button>
53-
<button
54-
type="button"
55-
class="button button--size-small button--width-full button--color-none"
56-
@click="showInviteCode = !showInviteCode"
57-
>
58-
I have an invite code
59-
</button>
6040
</form>
61-
</Card>
62-
<p v-if="!completedRegistration" class="text text--mt-1">
63-
Already have an account?
64-
<nuxt-link to="/auth/login">Login to your account</nuxt-link>
65-
</p>
41+
</div>
6642
</main>
6743
</template>
6844

6945
<script lang="ts">
7046
import { Component, Vue } from "vue-property-decorator";
7147
import { mapGetters } from "vuex";
72-
import Card from "@/components/Card.vue";
7348
import LargeMessage from "@/components/LargeMessage.vue";
74-
import Loading from "@/components/Loading.vue";
75-
import Input from "@/components/form/Input.vue";
76-
49+
import { User } from "../../types/auth";
7750
@Component({
78-
components: {
79-
Card,
80-
LargeMessage,
81-
Loading,
82-
Input,
83-
},
8451
computed: mapGetters({
8552
isAuthenticated: "auth/isAuthenticated",
53+
user: "auth/user",
8654
}),
55+
components: {
56+
LargeMessage,
57+
},
8758
})
8859
export default class Login extends Vue {
8960
name = "";
9061
email = "";
9162
password = "";
9263
invitedByUser = "";
64+
hasInviteCode = false;
65+
9366
isAuthenticated!: boolean;
94-
showInviteCode = false;
67+
user!: User;
9568
isLoading = false;
96-
completedRegistration = false;
97-
private register() {
69+
completed = false;
70+
71+
async login() {
9872
this.isLoading = true;
99-
this.$store
100-
.dispatch("auth/register", {
101-
email: this.email,
73+
try {
74+
const response = await this.$store.dispatch("auth/register", {
10275
name: this.name,
76+
email: this.email,
10377
password: this.password,
10478
invitedByUser: this.invitedByUser ? this.invitedByUser : undefined,
105-
})
106-
.then(() => {
107-
this.completedRegistration = true;
108-
})
109-
.catch((error) => {
110-
throw new Error(error);
111-
})
112-
.finally(() => {
113-
this.name = "";
114-
this.email = "";
115-
this.password = "";
116-
this.invitedByUser = "";
117-
this.isLoading = false;
11879
});
80+
if (response === "2fa") return this.$router.push("/auth/2fa");
81+
this.completed = true;
82+
} catch (error) {}
83+
this.isLoading = false;
84+
this.name = "";
85+
this.email = "";
86+
this.password = "";
11987
}
12088
121-
private created() {
122-
if (this.isAuthenticated) return this.$router.replace("/");
89+
created() {
90+
if (this.isAuthenticated)
91+
return this.$router.replace(
92+
(this.$route.query.redirect as string) || "/"
93+
);
12394
}
12495
}
12596
</script>
126-
127-
<style lang="scss" scoped>
128-
.button--size-large + .button--size-small {
129-
margin-top: 1rem;
130-
}
131-
</style>

store/auth.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ export const actions: ActionTree<RootState, RootState> = {
8888
}
8989
},
9090
async register({}, context) {
91-
try {
92-
return (await this.$axios.post("/auth/register", context)).data;
93-
} catch (error) {}
91+
return (await this.$axios.post("/auth/register", context)).data;
9492
},
9593
async safeRefresh({ state, dispatch }) {
9694
const token = state.tokens.token;

0 commit comments

Comments
 (0)