Follwoing the docs https://appwrite.io/docs/references/cloud/server-nodejs/account (email sessions) here & got:
⨯ Error: Login failed: account.createEmailSession is not a function
Which version of Appwrite and the node-appwrite SDK are you using?
"node-appwrite": "^13.0.0",
Are you using Cloud or self-hosting?
self-hosting
Which version are you running?
Version 1.5.7
In the newer versions of the SDK, createEmailSession() was changed to now be createEmailPasswordSession(). It still works the same way, just renamed to be clearer
👍 👍
I suggest to update the docs 🙂
The docs on the page you sent were already updated to show the changes https://appwrite.io/docs/references/1.5.x/server-nodejs/account#createEmailPasswordSession
Okay thanks for the quick support! Followup question: after login-in and try to sign out i got: `Logout failed: User (role: guests) missing scope (account)
`
using this code on lib/appwrite: ``` export async function loginUser(email: string, password: string) {
try {
const session = await account.createEmailPasswordSession(email, password);
// Log the session to verify
console.log("Session created:", session);
// Ensure session.$id is valid
if (!session.$id || session.$id.length > 36 || !/^[a-zA-Z0-9._-]+$/.test(session.$id)) {
throw new Error("Invalid session ID");
}
// Store session in cookies
cookies().set("my-custom-session", session.$id, {
httpOnly: true, // Cookie is accessible only by the web server
secure: true, // Cookie will be sent only over HTTPS
sameSite: "strict", // Cookie will be sent only in first-party contexts
});
return session;
} catch (error) {
console.error("Login failed:", error);
throw new Error("Login failed: " + error.message);
}
}
export const logoutUser = async () => { await account.deleteSession('current'); };
export const getSession = async () => { return await account.getSession('current'); }; ```
It looks like you're setting the wrong value for the cookie, you want to be storing the value from session.secret to the cookie instead. The reason it's failing it because it doesn't register as being logged in with the value being incorrect
Like this: cookies().set(session.secret, session.$id, {
httpOnly: true, // Cookie is accessible only by the web server
secure: true, // Cookie will be sent only over HTTPS
sameSite: "strict", // Cookie will be sent only in first-party contexts
});
?
Like this:
cookies().set("my-custom-session", session.secret, {
httpOnly: true,
secure: true,
sameSite: "strict",
});
Actually when I log-in it returned successfully - I try now with your suggestion thanks - got some rate limit😁 - how long it takes the rate limit?
Can I reset the rate limit when debugging?
There is an environment variable you can change to disable rate limits for self-hosted, set the value of _APP_OPTIONS_ABUSE to disabled in your .env file and then restart the docker containers
Recommended threads
- Authentication on custom Websocket Serve...
Hi, I want to use a custom Websocket Server (using Bun) for my application. However I cant really figure out authentication on custom servers. Session cookies ...
- My account got banned without obvious re...
Hello, I’m a normal user of Appwrite. Today I found my account was banned suddenly, and I can’t log in normally. I have only been doing normal development and...
- Realtime for files() works almost well, ...
I have been trying to make use of realtime, today (14.03.26) I have pulled all the latest versions of docker images, and sdk available. Whats working: - Conn...