Skip to content

Commit

Permalink
move getAuthorUrl responsibility to auth plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
gka committed May 24, 2020
1 parent ded3f38 commit e45b9a6
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const { plugins } = require('./plugins');

const providers = [];

const authPlugins = [];

function init(app, db, domain) {
app.use(
session({
Expand Down Expand Up @@ -65,25 +67,26 @@ function init(app, db, domain) {
// initialize auth plugins
plugins.forEach(plugin => {
if (typeof plugin.auth === 'function') {
plugin.auth({
providers,
passport,
app
});
authPlugins.push(
plugin.auth({
providers,
passport,
app
})
);
}
});
}

function getAuthorUrl(comment) {
if (comment.user_url) return comment.user_url;
switch (comment.provider) {
case 'mastodon':
return 'https://twitter.com/' + comment.name;
case 'twitter':
return 'https://twitter.com/' + comment.name;
case 'github':
return 'https://github.com/' + comment.name;
for (let i = 0; i < authPlugins.length; i++) {
if (typeof authPlugins[i].getAuthorUrl === 'function') {
const url = authPlugins[i].getAuthorUrl(comment);
if (url) return url;
}
}
return false;
}

module.exports = {
Expand Down

0 comments on commit e45b9a6

Please sign in to comment.