refactor(client): move Meteor auth calls behind AuthenticationContext

Merged
GG
6mo ago
+151-110

Summary

  • Add getLoginToken, loginWithCustomOauth, and wipeLocalAuth methods to AuthenticationContext, with matching useLoginToken, useLoginWithCustomOauth, and useWipeLocalAuth hooks in @rocket.chat/ui-contexts.
  • Migrate four consumers off direct meteor/* imports so that Meteor usage stays confined to the auth/user providers:
    • AuthorizationFormPage reads the stored login token via useLoginToken instead of Accounts.storageLocation.
    • useStoreCookiesOnLogin does the same, replacing Accounts._storedLoginToken().
    • useIframeCommands replaces Meteor.loginWithToken, the dynamic Meteor[loginWithX] call, and Meteor.logout with useLoginWithToken, useLoginWithCustomOauth, and UserContext.logout. The logoutCleanUp side effect is already wired through UserProvider's onLogout listener, so the inline sdk.call('logoutCleanUp', ...) is no longer needed.
    • useForceLogout collapses the Accounts._unstoreLoginToken() + Meteor.connection.setUserId(null) pair into a single wipeLocalAuth() call.

Test plan

  • OAuth authorize page: open /oauth/authorize?... while logged in and verify the hidden access_token field is populated and the form submits.
  • Login flow: confirm rc_uid and rc_token cookies are written after a successful login (Chrome DevTools › Application › Cookies).
  • Iframe integration: enable Iframe_Integration_receive_enable, then post login-with-token, call-custom-oauth-login, and logout messages from a parent frame and confirm each works.
  • Force logout: trigger an admin-issued force logout and confirm the session flag flips, the router lands on /login, and the stored login token is cleared from localStorage when the SDK transport is enabled.

Task: ARCH-2131

Summary by CodeRabbit

  • New Features

    • Custom OAuth login support with dynamic service handling.
    • Ability to read current login token and clear local auth state.
    • New hooks to access custom OAuth, login token, and wipe-local-auth actions.
  • Refactor

    • Internal auth flows updated to use context-based hooks for more consistent behavior across components.

Review Change Stack