-
Notifications
You must be signed in to change notification settings - Fork 17
/
app.vue
69 lines (63 loc) · 1.91 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
<div>
<div class="container mt-6" v-if="!firebaseUser">
<div class="column is-half is-offset-one-quarter">
<AuthFirebase
class="box px-5 py-5 mx-4"
title="Register"
@submit="register"
:form="registerForm"
:message="registerMessage"
v-if="showRegisterForm"
/>
<AuthFirebase
class="box px-5 py-5 mx-4"
title="Sign in"
@submit="signin"
:form="signinForm"
v-if="!firebaseUser && !showRegisterForm"
/>
</div>
<div class="level">
<div class="level-item has-text-centered">
<button class="button" @click="showRegisterForm = !showRegisterForm">
{{ toggleButtonText }}
</button>
</div>
</div>
</div>
<NuxtPage v-if="firebaseUser" />
</div>
</template>
<script setup>
const firebaseUser = useFirebaseUser();
const showRegisterForm = ref(false);
const registerMessage = ref();
const registerForm = ref({ email: "", password: "" });
const signinForm = ref({ email: "", password: "" });
const toggleButtonText = computed(() => {
return showRegisterForm.value ? "Sign in" : "Register";
});
const signin = () => {
signInUser(signinForm.value.email, signinForm.value.password);
signinForm.value = { email: "", password: "" };
};
const register = async () => {
console.log(registerForm.value);
const credentials = await createUser(
registerForm.value.email,
registerForm.value.password
);
registerForm.value = { email: "", password: "" };
if (credentials) {
registerMessage.value = `Successfully registered: ${credentials.user.email}`;
setTimeout(() => {
registerMessage.value = "";
}, 3000);
}
};
</script>
<style>
@import "https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css";
@import "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css";
</style>