Basic auth working

This commit is contained in:
2023-11-06 22:55:15 -05:00
parent edde4e79fd
commit 4a43b5813d
9 changed files with 138 additions and 99 deletions

View File

@@ -12,20 +12,13 @@
<div class="text-center q-pt-sm">
<div class="col text-h6">Log in</div>
</div>
<q-card-section>
<q-card-section v-if="errorMessage">
<div class="alert-box">
<strong>Error!</strong>
<br />
{{ errorMessage }}
</div>
</q-card-section>
<p>
{{
loggedInUser
? `Logged in as ${loggedInUser.name}`
: 'Not logged in'
}}
</p>
</q-card-section>
<q-card-section>
<q-form class="q-gutter-md">
@@ -93,44 +86,29 @@ strong {
}
</style>
<script lang="ts">
import { account } from 'src/boot/appwrite';
import { defineComponent } from 'vue';
<script setup lang="ts">
import { AppwriteException } from 'appwrite';
import { ref } from 'vue';
import { account } from 'boot/appwrite';
import { useRouter } from 'vue-router';
export default defineComponent({
defineOptions({
name: 'LoginPage',
setup() {
const loggedInUser = ref(null);
const email = ref('');
const password = ref('');
const current = this.$appwrite_account.get();
current.then(
function (response) {
console.log(response);
},
function (error) {
console.log(error);
}
);
const login = async (email, password) => {
await this.$appwrite_account.createEmailSession(email, password);
loggedInUser.value = await this.$appwrite_account.get();
if (loggedInUser.value.error) {
}
// TODO: Add error handling for failed login.
// TODO: Add forwarding for successful login.
};
return {
email,
password,
login,
};
},
});
const email = ref('');
const password = ref('');
const errorMessage = ref('');
const router = useRouter();
function login(email: string, password: string) {
account
.createEmailSession(email, password)
.then(() => {
router.push({ name: 'index' });
})
.catch((reason: AppwriteException) => {
errorMessage.value = reason.message;
});
}
</script>