]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/plugins/plugin-manager.ts
Support logout and add id and pass tests
[github/Chocobozzz/PeerTube.git] / server / lib / plugins / plugin-manager.ts
index f78b989f510fa0592574dd013a61997665b45c21..9d646b68976557da9f9d562a6c405be9e06438d9 100644 (file)
@@ -76,7 +76,7 @@ export class PluginManager implements ServerHook {
     return this.registeredPlugins[npmName]
   }
 
-  getRegisteredPlugin (name: string) {
+  getRegisteredPluginByShortName (name: string) {
     const npmName = PluginModel.buildNpmName(name, PluginType.PLUGIN)
     const registered = this.getRegisteredPluginOrTheme(npmName)
 
@@ -85,7 +85,7 @@ export class PluginManager implements ServerHook {
     return registered
   }
 
-  getRegisteredTheme (name: string) {
+  getRegisteredThemeByShortName (name: string) {
     const npmName = PluginModel.buildNpmName(name, PluginType.THEME)
     const registered = this.getRegisteredPluginOrTheme(npmName)
 
@@ -132,6 +132,22 @@ export class PluginManager implements ServerHook {
     return this.translations[locale] || {}
   }
 
+  onLogout (npmName: string, authName: string) {
+    const plugin = this.getRegisteredPluginOrTheme(npmName)
+    if (!plugin || plugin.type !== PluginType.PLUGIN) return
+
+    const auth = plugin.registerHelpersStore.getIdAndPassAuths()
+      .find(a => a.authName === authName)
+
+    if (auth.onLogout) {
+      try {
+        auth.onLogout()
+      } catch (err) {
+        logger.warn('Cannot run onLogout function from auth %s of plugin %s.', authName, npmName, { err })
+      }
+    }
+  }
+
   // ###################### Hooks ######################
 
   async runHook<T> (hookName: ServerHookName, result?: T, params?: any): Promise<T> {