Skip to content

fix: auth plugin, plugins purchased via razorpay, formatting and othe…#2066

Closed
deadlyjack wants to merge 8 commits intomainfrom
ajit/fetch-api-with-auth
Closed

fix: auth plugin, plugins purchased via razorpay, formatting and othe…#2066
deadlyjack wants to merge 8 commits intomainfrom
ajit/fetch-api-with-auth

Conversation

@deadlyjack
Copy link
Copy Markdown
Member

…r fixes

  • Refactored the WebSocket plugin implementation in websocket.js for improved readability and consistency.
  • Changed import statements in multiple settings files to use 'config' instead of 'constants' for better configuration management.
  • Updated URLs in settings and sidebarApps to use the new config structure.
  • Fixed a typo in sidebarApp.js variable name from $contaienr to $container.
  • Enhanced the canShowAds method in helpers.js to utilize the new config for checking the ad display conditions.

…r fixes

- Refactored the WebSocket plugin implementation in websocket.js for improved readability and consistency.
- Changed import statements in multiple settings files to use 'config' instead of 'constants' for better configuration management.
- Updated URLs in settings and sidebarApps to use the new config structure.
- Fixed a typo in sidebarApp.js variable name from $contaienr to $container.
- Enhanced the canShowAds method in helpers.js to utilize the new config for checking the ad display conditions.
@github-actions github-actions Bot added the translations Anything related to Translations Whether a Issue or PR label Apr 27, 2026
@deadlyjack
Copy link
Copy Markdown
Member Author

@greptile_apps review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

This PR centralises configuration into a new config.js module (replacing scattered constants and window.* globals), refactors the auth flow so getLoggedInUser is the single source of truth, fixes the $contaienr typo in sidebarApp.js, and reformats websocket.js. Two regressions were introduced alongside those improvements:

  • Sidebar user-menu always broken for logged-in users: handleUserIconClick fetches the user into user but renders the menu using the undeclared userInfo variable, causing a ReferenceError (caught silently) every time a logged-in user opens the context menu.
  • Rewarded-ad identity tracking silently broken: getRewardIdentity references the undeclared user variable and never returns its computed userId, so serverSideVerification.userId is always undefined.

Confidence Score: 2/5

Not safe to merge — two P0/P1 regressions break core user-facing flows for all logged-in users

A P0 (userInfo ReferenceError breaks the sidebar user menu for every logged-in user) and a P1 (getRewardIdentity undeclared user + missing return breaks rewarded-ad identity) are both on changed paths and will affect all users in production.

src/components/sidebar/index.js (undefined userInfo), src/lib/adRewards.js (undefined user + missing return in getRewardIdentity)

Important Files Changed

Filename Overview
src/components/sidebar/index.js Refactored user-icon click flow to inline menu rendering, but references undeclared userInfo instead of the fetched user — every logged-in menu open throws ReferenceError
src/lib/adRewards.js getRewardIdentity references undeclared user and never returns userId, silently breaking rewarded-ad server-side verification; canShowAds/isRewardedSupported correctly migrated from window.IS_FREE_VERSION to config.HAS_PRO
src/lib/auth.js Auth service cleaned up — logout no longer references undefined sidebar variables, getLoggedInUser caches with 10-min TTL and correctly returns null on 401
src/lib/config.js New config module centralising constants previously spread across constants.js and window.* globals; HAS_PRO exposed as a settable property
src/lib/installPlugin.js Migrated from constants to config; download-progress callback removed from readFile call, so large plugin installs will no longer show percentage in the loader
src/plugins/websocket/www/websocket.js Formatting-only refactor (tabs → spaces, wrapped long lines); logIfDebug still emits an unconditional log on every event regardless of the DEBUG flag
src/pages/plugin/plugin.js Migrated to config, Razorpay purchase path sets purchased = remotePlugin.owned directly; isExternalPurchase variable removed from prior version
src/sidebarApps/sidebarApp.js Typo fix: $contaienr$container across all usages; no functional changes

Sequence Diagram

sequenceDiagram
    participant U as User
    participant S as Sidebar (handleUserIconClick)
    participant A as auth.getLoggedInUser()
    participant C as config.BASE_URL

    U->>S: clicks user icon
    S->>A: await auth.getLoggedInUser()
    alt user is null (not logged in)
        A-->>S: null
        S->>C: CustomTabs.open(config.BASE_URL + /login)
    else user is logged in
        A-->>S: user object
        S->>S: toggle menu active
        Note over S: ReferenceError: userInfo is not defined
    end

    participant AR as adRewards (getRewardIdentity)
    participant AD as createRewardedAd

    U->>AR: watchOffer(offerId)
    AR->>AR: getRewardIdentity()
    Note over AR: user undeclared, ReferenceError caught
    AR->>AD: createRewardedAd(offer, step, sessionId)
    Note over AD: serverSideVerification.userId = undefined
Loading

Reviews (3): Last reviewed commit: "refactor: streamline user menu toggle lo..." | Re-trigger Greptile

Comment thread src/lib/auth.js Outdated
Comment on lines +82 to +86
if (res.ok) {
userContextMenu.el.classList.remove("active");
document.removeEventListener("click", handleClickOutside);
toast("Logged out successfully");
updateSidebarAvatar();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Undefined variables cause silent ReferenceError on logout

userContextMenu, handleClickOutside, and updateSidebarAvatar are not defined in auth.js — they live in src/components/sidebar/index.js. When the API logout succeeds (res.ok), this code throws a ReferenceError that is immediately caught and swallowed by the catch block (line 90). The dead block should be removed — auth.logout() should only own the server-side and native token teardown, not presentation logic.

Comment thread src/lib/adRewards.js Outdated
Comment thread src/lib/installPlugin.js
@@ -68,19 +68,12 @@ export default async function installPlugin(

let plugin;
if (
pluginUrl.includes(constants.API_BASE) ||
pluginUrl.includes(config.API_BASE) ||
pluginUrl.startsWith("file:") ||
pluginUrl.startsWith("content:")
) {
// Use fsOperation for Acode registry URL
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Download progress callback removed

The previous readFile call included a progress callback updating the loader dialog with a download percentage. Removing it means users installing larger plugins from the Acode registry no longer see progress — the loader will appear stuck.

deadlyjack and others added 3 commits April 28, 2026 05:03
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@deadlyjack
Copy link
Copy Markdown
Member Author

@greptile_apps review again

Comment thread src/components/sidebar/index.js Outdated
Comment on lines 151 to 168
async function updateUserMenuInfo() {
try {
const userInfo = await auth.getUserInfo();
if (userInfo) {
const menuName = userContextMenu.el.querySelector(".user-menu-name");
const menuEmail = userContextMenu.el.querySelector(".user-menu-email");
menuName.textContent = userInfo.name || "Anonymous";
if (userInfo.isAdmin) {
menuName.innerHTML += ' <span class="badge">Admin</span>';
}
menuEmail.textContent = userInfo.email || "";
}
const userInfo = await auth.getLoggedInUser();
const menuName = userContextMenu.el.querySelector(".user-menu-name");
const menuEmail = userContextMenu.el.querySelector(".user-menu-email");
menuName.content = (
<div style={{ display: "flex" }}>
{Boolean(userInfo.verified) && (
<span className="icon verified"></span>
)}
{userInfo.name}
{Boolean(userInfo.acode_pro) && <span className="badge">Pro</span>}
</div>
);
menuEmail.textContent = userInfo.email || "";
} catch (error) {
console.error("Error fetching user info:", error);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Null dereference in updateUserMenuInfo when getLoggedInUser() returns null

auth.getLoggedInUser() explicitly returns null when the server responds with 401 (e.g., session expired between the handleUserIconClick guard and this call, or the token was revoked). Accessing userInfo.verified, userInfo.name, userInfo.acode_pro, and userInfo.email on a null value all throw TypeError. The catch block swallows the error silently, so the menu is rendered empty with no user feedback.

Add a null guard after the await:

const userInfo = await auth.getLoggedInUser();
if (!userInfo) return;

@deadlyjack
Copy link
Copy Markdown
Member Author

@greptile_apps review again

Comment thread src/components/sidebar/index.js Outdated
deadlyjack and others added 2 commits April 28, 2026 05:25
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
fix: clear loggedInUser and remove cached user data on logout
@Acode-Foundation Acode-Foundation deleted a comment from greptile-apps Bot Apr 28, 2026
@deadlyjack deadlyjack closed this Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

translations Anything related to Translations Whether a Issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant