-
Notifications
You must be signed in to change notification settings - Fork 77
Description
The getUserKarmaFromCurrentSubreddit method works when making the request as a moderator but not when making the request as a user. As a consequence, a user cannot get their own karma from the subreddit: an error is thrown. The behaviour is non-obvious (not documented in code, doesn't behave intuitively) so my guess is this is a bug on the reddit backend (?) i.e: the endpoint requires moderator permissions for all usernames without providing an exception for the authenticated user's username.
To reproduce: as a user (not moderator) access an app that uses getUserKarmaFromCurrentSubreddit() and receive this error:
Error: 7 PERMISSION_DENIED: only moderators can access user karma for subreddit
Discussed in Discord here: https://discord.com/channels/1050224141732687912/1050227353311248404/1458164688591388732
devvit/packages/reddit/src/models/User.ts
Lines 432 to 442 in 62336a6
| /** | |
| * Returns the karma for this User in the current subreddit. | |
| * | |
| * @returns The GetUserKarmaForSubredditResponse, containing the user's karma for comments and posts in the subreddit. | |
| */ | |
| async getUserKarmaFromCurrentSubreddit(): Promise<GetUserKarmaForSubredditResponse> { | |
| return await getRedditApiPlugins().Users.GetUserKarmaForSubreddit({ | |
| username: this.username, | |
| subredditId: context.subredditId, | |
| }); | |
| } |
devvit/packages/reddit/src/RedditClient.ts
Lines 684 to 692 in 62336a6
| /** | |
| * Returns the karma for a given user in the current subreddit. | |
| * | |
| * @param username - The username of the user to get the karma for. e.g. 'spez' | |
| * @returns The GetUserKarmaForSubredditResponse, containing the user's karma for posts and comments in the subreddit. | |
| */ | |
| getUserKarmaFromCurrentSubreddit(username: string): Promise<GetUserKarmaForSubredditResponse> { | |
| return User.getUserKarmaFromCurrentSubreddit(username); | |
| } |