-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
add session context for a user mongodb #7436
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me!
@sinedied do you mind giving this a look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @crisjy !
The context handling looks fine here, but you're missing user handling, which is needed to list/delete sessions otherwise you have no distinction of users.
What we did in the other CosmosDB implementation is make userId
parameter optional in the DB options and set it to anonymous
by default to keep compatibility with other implementation (or when user handling is not needed).
{ upsert: true } | ||
); | ||
} catch (error) { | ||
console.log("Error setting context", error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to throw so these errors can be identified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw errors for this
try { | ||
await this.collection.deleteMany({}); | ||
} catch (error) { | ||
console.log("Error clearing sessions:", error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to throw so these errors can be identified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw errors for this
async clearAllSessions() { | ||
await this.initialize(); | ||
try { | ||
await this.collection.deleteMany({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would delete all sessions for all users, which might not be the intended behavior... I think you missed the user handling here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, add user id as handle for sessions, thank you for your comment!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to update this call to filter it for the current user only
@crisjy let me know when this is ready for another look! |
@jacoblee93 @sinedied resolve comments for this pr, sorry for delay, could you help me to have a look? thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the update with userId support looks great!
Though you forgot to add the filter for the current userId on the getAllSessions() and clearAllSessions() methods, as it should apply only to the current users. Should be a quick fix :)
|
||
async getAllSessions(): Promise<ChatSessionMongo[]> { | ||
await this.initialize(); | ||
const documents = await this.collection.find().toArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing user filter here
async clearAllSessions() { | ||
await this.initialize(); | ||
try { | ||
await this.collection.deleteMany({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to update this call to filter it for the current user only
Fixes # (issue)