Error: Appwrite Login Authentication failed due to account.createEmailSession function not recognized as a valid function

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!

Answer №1

Currently, I am also going through a tutorial, but my choice is Vite and React. To resolve this issue, I switched to using createEmailPasswordSession(). Although it worked for me, I'm uncertain if it is applicable to Vue applications.

Answer №2

Upon comparing v1.4 and v1.5 of appwrite, it appears that:

v1.4: account.createEmailSession v1.5: account.createEmailPasswordSession

https://appwrite.io/threads/1215260589882867782

Even though I hadn't made any code changes or updates, restarts, or rebuilds, I encountered the same issue. It's possible that I simply didn't notice earlier because I had been using an authenticated session for weeks.

Answer №3

Give the regular createSession() a shot instead, it worked like a charm for me.

Answer №4

import { Client, Account } from 'appwrite'; const API_ENDPOINT = 'https://my-appwrite-server.com/v1'; // Insert your Appwrite server endpoint here const PROJECT_ID = 'my-project-id'; // Enter your project ID here const LoginFormComponent = () => {

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 LoginFormComponent;

Answer №5

Consider utilizing createEmailPasswordSession in place of createEmailSession for better results.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Challenges with date formatting arise for Spanish speakers when the date returns as NaN or an Invalid

I have been working on an Angular app Objective: My aim is to allow users to input dates in Spanish format (DD/MM/YYYY) and display them as such, while converting them back to English format when saving the data to the Database. Issue: One problem I enco ...

Stop the default drag behavior on an input range element in VueJS

Is there a way to disable the default drag functionality of an input range element without affecting the click feature? Users should be able to change values by clicking instead of dragging. <input type="range" min="0" max=& ...

Having trouble displaying API values in b-form-select component in Vue.js?

I am using an API to fetch users data and I want to bind these users to a b-form-select component in Bootstrap Vue. However, after making the request, I only see "null" in the b-form-select. Here is my request: getAllUsers() { axios.get(&a ...

Retrieving data from multiple mongo collections and merging selected attributes from the output

I'm attempting to query a Mongo collection, extract an attribute from each object returned, use that attribute to retrieve data from another collection, and then combine the data. I am unsure of how to achieve this on mongoDB. To break it down, what I ...

Unable to insert HTML code into a div upon clicking an image button

I am in the process of developing a website dedicated to radio streams, and I was advised to utilize Jquery and AJAX for loading HTML files into a div upon button click. This way, users wouldn't have to load an entirely new page for each radio stream. ...

Deleting a row from a table in AngularJS can be accomplished by following these steps

I am having trouble with deleting rows from a table using angularjs. When I try to delete a row, it ends up deleting the previous row instead of the correct one. How can I fix this issue? Please check out the working DEMO Here is the code snippet: < ...

Tips on adding a base64 encoded image string to a JSON object using JavaScript

I'm trying to convert an image file into a JSON object using JavaScript. I've managed to turn the image into a string by utilizing base64 encoding, but I'm unsure how to then convert this string into a JSON object. Can anyone help? ...

The button labeled "issett" is malfunctioning

Hey there, so I've created a registration form using jQuery and PHP that validates user input in real-time as they type. Once all the information is correct, I want to allow the user to submit the form. My plan is to write an if statement that checks ...

Deciding on excluding empty key:value pairs from an object for various filtering needs

One of the features in my app allows users to filter results by "blood group" and "city", along with other areas. The information is retrieved from a database using Axios for Vuejs, incorporating query strings within the URL. For example: http://example.co ...

`Loading CSS and JS files in node.js: A step-by-step guide`

I've searched through numerous similar questions without success, so I'm reaching out for help. My folder structure looks like this: Source Code Frontend Graphs.html Graphs.css Temperature.js Server_Backend server.js I aim ...

Creating a Route in Angular 2 for a Component other than the one initialized with the bootstrap function

I am currently in the process of working on a project involving Angular2. If you are interested in understanding why I need to do what I am about to explain, please take a look at this issue. The main component in my project is called AppComponent and it ...

Ways to verify if the user has inputted a typeahed value

My code snippet looks like this: var students = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('fullName'), queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { ...

Getting the value from the object that holds the Provider/Consumer using React's Context API

Below is a demonstration using the Context API object with a library called 'react-singleton-context'. Check it out here. In my Menu.js file, I have the code snippet console.log(useSharedDataContext()). This displays an object containing Consume ...

Testing form submission in React with React Testing Library and checking if prop is called

Feel free to check out the issue in action using this codesandbox link: https://codesandbox.io/s/l5835jo1rm To illustrate, I've created a component that fetches a random image every time a button is clicked within the form: import { Button } from " ...

Tips on revealing TypeScript modules in a NodeJS environment

Currently, I am working on developing a TypeScript library. My goal is to make this library compatible with both TypeScript and JavaScript Node projects. What would be the most effective approach for achieving this? Should I create two separate versions ...

What is the recommended way to delete Mesh objects in ThreeJS?

What are some effective methods in ThreeJS for creating and deleting Meshes (comprised of Geometry and Materials) efficiently? I want to showcase latitude/longitude points on a revolving 3D globe. Each point should be clickable, revealing additional infor ...

Tips for specifically targeting the clicked table row using angularJS directives ng-show and ng-hide

Seeking assistance with implementing a toggle function in an angularJS app for showing/hiding a specific table data section. Currently, the toggling functionality is working, but it toggles every row in the table instead of just the clicked row. See this e ...

Manipulating data with Entity Framework using Knockout and AngularJS

When creating a knockout restful service, the first attempt was successful. However, upon implementing it in Angular, there were issues with the database displaying an ID with other fields labeled as undefined. Trying to fix this, I recreated the WCF Servi ...

The functionality of Ajax loading content will fail when the link is already loaded

I am currently using an ajax script that dynamically replaces the content of #main with the contents of a loaded page based on the clicked link. For example, clicking on rddd would replace #main with the content of about.php. However, I encountered an is ...

Trigger a keyframe animation upon initial click and then reverse playback on the subsequent click

I'm struggling to create a wave animation that fills the screen up to a certain point and stops on the first click of a navigation menu. I've attempted to have it play in reverse when the navigation menu is clicked again, but it's not workin ...