prokawsarOriginal post
Web Developer
Following https://appwrite.io/docs/references/cloud/server-nodejs/users#createSession
Here is my code sample:
try {
const response = await users.create(ID.unique(), email, phone);
const session = await users.createSession(response.$id);
return Response.json({
success: true,
message: "User created successfully!",
user: response,
session: session
});
} catch (AppWriteError: unknown) {
const error = AppWriteError as AppwriteException;
return Response.json({
success: false,
message: error.message,
user: null
});
}
How to create a session for the newly created user?
I know creating account will make a session, but I need to create users with email and phone.
Thanks
Summary
Developers are encountering a "Server error" when attempting to create a session for new users with email and phone using the Appwrite framework. The issue lies in attempting to create a session immediately after creating a user. To resolve this, developers should call the createSession method with the user's $id, obtained after creating the user.