julianlam / nodebb-plugin-session-sharing

Allows login sessions from your app to persist in NodeBB
MIT License
86 stars 66 forks source link

Add host whitelist #94

Closed nesro closed 3 years ago

nesro commented 3 years ago

Hi Julian, while in migration and testing phase or in some complex setup a host whitelist might be useful. I've added it to settings with default settings (empty valu) that has no effect.

I also notices that redirect values doesn't take place immediately so I added an option to call admin.reload in the save popup.

Thanks for the great work you're doing!

Tomas

julianlam commented 3 years ago

Hi @nesro, thanks for opening this PR! I think the usefulness is limited, but it is a nice-to-have so I will merge it.

One question, however...

I also notices that redirect values doesn't take place immediately

Did you mean the guestRedirect setting is not automatically set for the running instance when the setting is updated? Does this also apply for the new hostWhitelist setting as well?

Reason being – we have a new way of managing plugin settings. Instead of saving them locally like we do in this plugin, you can simply call const { hostWhitelist } = await meta.settings.get('session-sharing'); to always get the latest value in whatever method needs it, so if this is the case, I'd rather have you revert the change to the "onSave toast", update how you retrieve the hostWhitelist setting, and I will do the same for guestRedirect after the merge :smile:

nesro commented 3 years ago

Hi @julianlam, sorry for the delay in my response.

I reverted changes to the "onSave toast" and used the code const { hostWhitelist } = await meta.settings.get('session-sharing'); and it works perfectly (no need to restart the forum to see the changes).

I added two more features:

  1. You can now use the wildcard %1 in the all overrides.
  2. You can now set the Edit Profile override.

Little bit of background: We are using our own site to register, log in and edit users. Session sharing plugin is used just to be able to log into the forum, but we want users to edit their profiles on our site. The %1 wildcard - last url visited on the forum is used to be able to return to the forum after you're done with registration, login or editing profile.

I've also refactored the static/lib/main.js a little bit because there was lot of repetitive code. I also added a redirection for the "Edit Profile" into the library.js file. That's handling the case you visit the edit profile url directly.

When I used the better loading of settings, I've edited the guestRedirect part too.

If you think this PR contains a lot of things at once (host whitelist, edit profile redirect, guest redirect), I can split the changes into multiple PR, but I think it will be easier to test at once.

Thanks Tomas

nesro commented 3 years ago

Hi again @julianlam, I found some more issues as I am testing this. I added redirect for login and register to the server too in case you go directly to this url (someone might have it as a bookmark). And I put the %1 wildcard replacing on the client side to try block with fallback in case encodeURIComponent fails for any reason.

julianlam commented 3 years ago

You know, you keep doing this and I will just make you a maintainer :smiling_imp:

julianlam commented 3 years ago

v4.7.0