doc: add login function

This commit is contained in:
Leon Xu committed 2021-12-31 11:52:40 -08:00
1 parent 40edc6c33d
commit f1b8ddf889
1 file changed
+21 -1
+21 -1
View File
@@ -7,6 +7,7 @@
<!-- Login --> <!-- Login -->
<form <form
@submit.prevent="login"
action="" action=""
class="p-8 flex flex-col bg-light-grey rounded-md shadow-lg" class="p-8 flex flex-col bg-light-grey rounded-md shadow-lg"
> >
@@ -63,6 +64,9 @@
<script> <script>
import { ref } from "vue"; import { ref } from "vue";
import { supabase } from "../supabase/init";
import { useRouter } from "vue-router";
export default { export default {
name: "login", name: "login",
setup() { setup() {
@@ -70,10 +74,26 @@ export default {
const email = ref(null); const email = ref(null);
const password = ref(null); const password = ref(null);
const errorMsg = ref(null); const errorMsg = ref(null);
const router = useRouter();
// Login function // Login function
const login = async () => {
try {
const { error } = await supabase.auth.signIn({
email: email.value,
password: password.value,
});
if (error) throw error;
router.replace({ name: "Home" });
} catch (error) {
errorMsg.value = `Error: ${error.message}`;
setTimeout(() => {
errorMsg.value = null;
}, 5000);
}
};
return { email, password, errorMsg }; return { email, password, errorMsg, login };
}, },
}; };
</script> </script>