-
Notifications
You must be signed in to change notification settings - Fork 13k
chore: remove other logins tokens method calls #35754
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
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { Users } from '@rocket.chat/models'; | ||
| import { Accounts } from 'meteor/accounts-base'; | ||
|
|
||
| export const removeOtherTokens = async function (userId: string, connectionId: string): Promise<void> { | ||
| const currentToken = Accounts._getLoginToken(connectionId); | ||
|
|
||
| await Users.removeNonLoginTokensExcept(userId, currentToken); | ||
|
Comment on lines
+4
to
+7
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. export const removeOtherTokens = async function (userId: string, connectionId: string): Promise<void> {
try {
const currentToken = Accounts._getLoginToken(connectionId);
if (!currentToken) {
throw new Error('No valid login token found');
}
await Users.removeNonLoginTokensExcept(userId, currentToken);
} catch (error) {
console.error(`Failed to remove tokens for user ${userId}:`, error);
throw error;
}
};The removeOtherTokens function lacks error handling for token retrieval and removal operations, which could result in silent failures. This issue appears in multiple locations:
Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,6 +181,8 @@ export interface IUsersModel extends IBaseModel<IUser> { | |
|
|
||
| removeNonPATLoginTokensExcept(userId: any, authToken: any): any; | ||
|
|
||
| removeNonLoginTokensExcept(userId: any, authToken: any): any; | ||
|
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. removeNonLoginTokensExcept(userId: string, authToken: string): Promise<UpdateResult>;The removeNonLoginTokensExcept method uses 'any' as the return type, which reduces type safety and makes error handling more difficult. This issue appears in multiple locations:
Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. 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. removeNonLoginTokensExcept(userId: string, authToken: string): Promise<UpdateResult>;The removeNonLoginTokensExcept method uses 'any' type for parameters, reducing type safety and potentially leading to runtime errors. This issue appears in multiple locations:
Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
|
|
||
| removeRoomsByRoomIdsAndUserId(rids: any, userId: any): any; | ||
|
|
||
| removeRolesByUserId(uid: IUser['_id'], roles: IRole['_id'][]): Promise<UpdateResult>; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1324,6 +1324,21 @@ export class UsersRaw extends BaseRaw<IUser, DefaultFields<IUser>> implements IU | |
| ); | ||
| } | ||
|
|
||
| removeNonLoginTokensExcept(userId: IUser['_id'], authToken: string) { | ||
| return this.col.updateOne( | ||
| { | ||
| _id: userId, | ||
| }, | ||
| { | ||
| $pull: { | ||
| 'services.resume.loginTokens': { | ||
| hashedToken: { $ne: authToken }, | ||
| }, | ||
| }, | ||
| }, | ||
| ); | ||
|
Comment on lines
+1327
to
+1339
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. removeNonLoginTokensExcept(userId: IUser['_id'], authToken: string) {
if (!userId || !authToken || typeof authToken !== 'string' || authToken.trim() === '') {
throw new Error('Invalid userId or authToken parameters');
}
return this.col.updateOne(
{
_id: userId,
},
{
$pull: {
'services.resume.loginTokens': {
hashedToken: { $ne: authToken },
},
},
},
);
}The removeNonLoginTokensExcept method lacks validation for userId and authToken parameters, which could lead to security issues. This issue appears in multiple locations:
Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
| } | ||
|
|
||
| removeRoomsByRoomIdsAndUserId(rids: IRoom['_id'][], userId: IUser['_id']) { | ||
| return this.updateMany( | ||
| { | ||
|
|
||
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.
The removeOtherTokens function call lacks proper error handling, which could lead to unhandled exceptions and poor user experience.
This issue appears in multiple locations:
Please wrap the removeOtherTokens function call in a try-catch block to handle potential errors gracefully and provide meaningful error messages.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.