Browse Source

Add beforeAttemptNonPreboundSession hook

JC Brand 4 months ago
parent
commit
bef6946255
1 changed files with 9 additions and 0 deletions
  1. 9 0
      src/headless/utils/init.js

+ 9 - 0
src/headless/utils/init.js

@@ -378,6 +378,15 @@ async function getLoginCredentialsFromSCRAMKeys () {
  */
 export async function attemptNonPreboundSession (credentials, automatic) {
     const { api } = _converse;
+    /**
+     * *Hook* to allow 3rd party plugins to provide their own login credentials.
+     * @event _converse#beforeAttemptNonPreboundSession
+     */
+    const { credentials: new_creds } = await api.hook("beforeAttemptNonPreboundSession", this, {
+        credentials,
+        automatic,
+    });
+    if (new_creds) return connect(new_creds);
 
     if (api.settings.get("authentication") === LOGIN) {
         const jid = _converse.session.get('jid');