首页 > 解决方案 > 如何编辑 url 以注销 ApostropheCMS

问题描述

我正在研究一种将 OAuth2 登录到 ApostropheCMS 的特定策略。登录系统后,我需要通过允许我执行 OAuth2 流程的身份服务器的 url 关闭会话。

不要使用http://localhost:3000/logout,而是使用 http ://localhost:port/auth/oauth2/logout。但我找不到使用 ApostropheCMS 中的注销链接编辑 url 的位置。

标签: apostrophe-cms

解决方案


我相信您是说您不需要复制注销功能(您已经这样做了),您需要更改管理栏中的注销链接。幸运的是,有一个好方法可以做到这一点。

像大多数模块一样,该apostrophe-login模块在一个名为addAdminBarItems. 该方法如下所示:

    self.addAdminBarItems = function() {
      var items = [];
      var key;
      if (self.options.resetKnownPassword) {
        key = self.__meta.name + '-reset-known-password';
        self.apos.adminBar.add(key, 'Change Password', null);
        items.push(key);
      }
      key = self.__meta.name + '-logout';
      self.apos.adminBar.add(key, 'Log Out', null, { last: true, href: '/logout' });
      items.push(key);
      if (items.length > 1) {
        self.apos.adminBar.group({
          label: 'Account',
          items: items,
          last: true
        });
      }
    };

我们可以覆盖它以满足我们的需要。

lib/modules/apostrophe-login/index.js在项目级别创建。不要从 node_modules 复制和粘贴整个内容,这不是必需的,我们在这里覆盖了一种方法。Apostrophe 将自动看到这一点并将我们的更改应用于原始文件。

文件如下所示:

// in lib/modules/apostrophe-login/index.js of your project
module.exports = {
  construct: function(self, options) {
    self.addAdminBarItems = function() {
      key = self.__meta.name + '-logout';
      self.apos.adminBar.add(key, 'Log Out', null, { last: true, href: '/anywhere/you/want/it/to/go' });
    };
  }
};

这将替换我们需要更改的方法,而不会更改任何其他内容。


推荐阅读