admin管理员组文章数量:1327994
I follow this tutorial with Vue, Appwrite
src/appwrite/index.js
import { Client, Databases, Account } from "appwrite";
const client = new Client();
client
.setEndpoint(";)
.setProject("PROJECT-ID"); // Replace 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>
Register function is OK. New user is created in Appwrite Console/Auth.
But when clicking to Login button, it throws an error
Uncaught (in promise) TypeError: account.createEmailSession is not a function
I cannot find a proper answer anywhere. Can someone explain it?
I follow this tutorial with Vue, Appwrite 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"); // Replace 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>
Register function is OK. New user is created in Appwrite Console/Auth.
But when clicking to Login button, it throws an error
Uncaught (in promise) TypeError: account.createEmailSession is not a function
I cannot find a proper answer anywhere. Can someone explain it?
Share Improve this question asked Mar 16, 2024 at 6:05 user16806454user16806454 4211 gold badge5 silver badges9 bronze badges6 Answers
Reset to default 5Using Vite instead of React, this error was solved on my end by using createEmailPasswordSession()
instead. Not sure if that would work for a Vue app.
It looks like the difference between v1.4 and v1.5 of appwrite:
- v1.4:
account.createEmailSession
- v1.5:
account.createEmailPasswordSession
https://appwrite.io/threads/1215260589882867782
I had the same issue, though I had no code changes, and no updates, restarts, rebuilds, etc, I could tell. Maybe I had just not noticed because I was using an authenticated session for weeks.
Try using normal createSession()
instead.
import { Client, Account } from 'appwrite';
const API_ENDPOINT = 'https://your-appwrite-endpoint./v1'; // Replace with your Appwrite endpoint
const PROJECT_ID = 'your-project-id'; // Replace with your project ID
const LoginForm = () => {
const client = new Client()
.setEndpoint(API_ENDPOINT)
.setProject(PROJECT_ID);
const account = new Account(client);
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
try {
const session = await account.createEmailPasswordSession(email, password);
console.log(session)
} catch (error) {
console.error('Login failed:', error);
}
};
return (
<form onSubmit={handleSubmit}>
{/* Input fields for email and password */}
<button type="submit">Login</button>
</form>
);
};
export default LoginForm;
I had same issue, but it worked when i replaced the the fucntion createEmailSession
with createEmailPasswordSession
.
change your appwrite version
v1.4: account.createEmailSession v1.5: account.createEmailPasswordSession
https://appwrite.io/threads/1215260589882867782
本文标签: javascriptAppwrite Login Auth TypeError accountcreateEmailSession is not a functionStack Overflow
版权声明:本文标题:javascript - Appwrite Login Auth: TypeError: account.createEmailSession is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742245449a2439185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论