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
- The current user is not authorized to pe...
I want to create a document associated with user after log in with OAuth. The user were logged in, but Appwrite said user is unauthorized. User is logged in wi...
- self-hosted auth: /v1/account 404 on saf...
Project created in React/Next.js, Appwrite version 1.6.0. Authentication works in all browsers except Safari (ios), where an attempt to connect to {endpoint}/v1...
- delete document problems
i don't know what's going on but i get an attribute "tournamentid" not found in the collection when i try to delet the document... but this is just the document...