-
-
Notifications
You must be signed in to change notification settings - Fork 89
fix: Login Error #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Login Error #390
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,18 +143,20 @@ const getUserByUserId = async (userId: string) => { | |
}; | ||
|
||
const login = async (email: string, password: string) => { | ||
// Delete current session, if any | ||
try { | ||
await account.deleteSessions(); | ||
const response = await account.createEmailPasswordSession(email, password); | ||
|
||
if (!response) { | ||
await account.deleteSession("current"); | ||
} catch (error: any) { | ||
if (error?.type !== "general_unauthorized_scope") { | ||
throw new Error("Login failed"); | ||
} | ||
} | ||
|
||
const accountId: string = response && response.userId; | ||
|
||
try { | ||
const session = await account.createEmailPasswordSession(email, password); | ||
const { userId: accountId, expire } = session; | ||
const user = await getUserByAccountId(accountId); | ||
return user; | ||
return { user, expires: new Date(expire) }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will expire immediately, you need to add some buffer time. I prefer to add 2 days There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to know why would this expire immediately? As per the Appwrite docs, the Also, the cookie expire time is set to be in sync with the appwrite session validation (1 year by default), that can be changed. Cookie expire time (matches appwrite session length): Appwrite console to set session length (auth > security): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me test that out locally, and then finalize the PR |
||
} catch (error: any) { | ||
console.log(error); | ||
throw new Error(error.message); | ||
|
Uh oh!
There was an error while loading. Please reload this page.