Looking for help with Vue and Appwrite? Check out this tutorial: https://appwrite.io/docs/tutorials/vue/step-1
src/appwrite/index.js
import { Client, Databases, Account } from "appwrite";
const client = new Client();
client
.setEndpoint("https://cloud.appwrite.io/v1")
.setProject("PROJECT-ID"); // Don't forget to replace 'PROJECT-ID' with your project ID
export const account = new Account(client);
export const databases = new Databases(client);
src/store/user.js
import { ID } from 'appwrite';
import { account } from "@/appwrite";
import { reactive } from "vue";
export const user = reactive({
current: null,
async init() {
try {
this.current = await account.get();
} catch (e) {
this.current = null;
}
},
async register(email, password) {
await account.create(ID.unique(), email, password);
await this.login(email, password);
},
async login(email, password) {
await account.createEmailSession(email, password);
window.location.href = "/";
},
async logout() {
await account.deleteSession("current");
this.current = null;
},
});
src/pages/auth/Login.vue
<script setup>
import { user } from "@/store/users";
import { ref } from "vue";
const email = ref("");
const password = ref("");
</script>
<template>
<section>
<h1>Login or register</h1>
<form>
<input type="email" placeholder="Email" v-model="email" />
<input type="password" placeholder="Password" v-model="password" />
<div>
<button type="button" @click="user.login(email, password)">
Login
</button>
<button type="button" @click="user.register(email, password)">
Register
</button>
</div>
</form>
</section>
</template>
The registration function works fine as it creates a new user in the Appwrite Console/Auth. However, there seems to be an issue when clicking the Login button, showing an error message:
Uncaught (in promise) TypeError: account.createEmailSession is not a function
If you have any insights or solutions to this problem, please share!