JavaScript API
Gatey exposes its public runtime surface under the WP Suite global:
globalThis.WpSuite.plugins.gatey(plugin object)globalThis.WpSuite.plugins.gatey.cognito(Cognito/session helpers)
All helper methods are async and return a Promise unless noted otherwise.
Runtime helpers (shared WP Suite contract)
WP Suite plugins share a small common runtime contract (from @smart-cloud/wpsuite-core).
Helper accessors
If you are bundling @smart-cloud/wpsuite-core, you can also use:
getWpSuite()→ returns the globalWpSuiteobject (orundefined)getPlugin("gatey" | "...")→ returns a plugin object from the registry
(These are thin wrappers around globalThis.WpSuite.)
Plugin status
WpSuite.plugins.gatey.status can be one of:
unavailable— plugin not present / not initialized yetinitializing— booting upavailable— ready to useerror— failed to initialize
Wait until Gatey is ready
There are three common ways to wait:
1) onReady(cb)
globalThis.WpSuite?.plugins?.gatey?.onReady?.(() => {
console.log("Gatey is ready");
});
2) availability() (await-ready with timeout)
Resolves to available, unavailable, or error (it never returns initializing).
const res = await globalThis.WpSuite?.plugins?.gatey?.availability?.();
if (res !== "available") {
console.warn("Gatey not available:", res);
}
3) Gatey core wrappers (waitForGateyReady)
If your build includes the Gatey core package, you can use its convenience wrappers:
getGateyPlugin()waitForGateyReady(timeoutMs = 8000)
These are thin helpers on top of the events below.
Readiness / error events
Gatey emits DOM events you can listen to:
wpsuite:gatey:readywpsuite:gatey:error
window.addEventListener("wpsuite:gatey:ready", () => console.log("ready"));
window.addEventListener("wpsuite:gatey:error", () => console.log("error"));
Cognito helper methods
The methods below live under WpSuite.plugins.gatey.cognito.
| Method | Returns | Use case |
|---|---|---|
getUsername() | string | Display the current username. |
getUserAttributes() | object | Prefill a form with profile data. |
getMfaPreferences() | object | Show MFA status. |
clearMfaPreferences() | void | One-click TOTP disable. |
isAuthenticated() | boolean | Guard a route or action. |
isInGroup("admin") | boolean | Role-based UI. |
getGroups() | string[] | Render a badge list. |
getRoles() | string[] | IAM role switcher / role-aware UI. |
getScopes() | string[] | Scope-aware buttons. |
getPreferredRole() | string | Auto-select a role. |
setLanguage("en") | void | Switch the Authenticator’s UI language. |
Example: show user and roles
const gatey = globalThis.WpSuite?.plugins?.gatey;
const cognito = gatey?.cognito;
const ok = (await gatey?.availability?.()) === "available";
if (!ok) return;
console.log("User:", await cognito.getUsername());
console.log("Roles:", await cognito.getRoles());
Notes
- Always guard calls with optional chaining (
?.) in case Gatey is not installed on the page. - If you are writing a plugin/theme that depends on Gatey, prefer
availability()/onReady()/waitForGateyReady()over polling.