
I'm using Appwrite to create an email session with users. At the moment, I do very basic checks within the login form component that check if the password is longer than 8 characters. I then call a function in a separate utility file that handles the login. How can I check for errors such as no user found? Is there perhaps a boilerplate for an appwrite login and register function that I can look at? I'm fairly new to React, is code within a component secure, i.e: can I call the createEmailSession
from the component file?

You can put it in the component. It's up to you how you want to organize your code.
To handle errors, wrap in try/catch, and then handle the exception

Hi @larkx , here is a pseudo example using try catch:
import { sdk } from 'appwrite';
const loginUser = async (email, password) => {
try {
await sdk.account.createEmailSession(email, password);
} catch (error) {
if (error.code === 'user-not-found' // any other error you are checking for) {
console.log('User not found. Please check your credentials.');
} else {
console.log('An error occurred:', error.message);
}
}
};```
Recommended threads
- React native app login via Safari
Hi! I deployed for debug my React Native app in web, chrome everythink works well but in safari on mac and ios I cant login. I found this one error in safari co...
- Invalid credentials after migration
Hi everyone! After migrating our self-hosted Appwrite 1.3.1 to another server (staging, so a different domain), we are now getting 'Invalid credentials' when ...
- implement caching
It it possible to cache response for few minutes? I dont want to create function or implement a whole reverse server just to cache it in somewhere ?
