FastComments.com

Add Comments With MemberSpace

With FastComments, we can set up exclusive Members-only commenting when combined with MemberSpace.

We can also allow anonymous commenting if desired at the same time when a user is logged in, and can even set custom badges based on the user's membership!

The Code Internal Link

We can easily connect FastComments with MemberSpace with a small code snippet:

FastComments MemberSpace Snippet
Copy Copy
1
2<script src="https://cdn.fastcomments.com/js/embed-v2.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5 (function () {
6 const tenantId = 'demo';
7 const ALLOW_ANON = false;
8 const LOGIN_URL = 'https://example.com/login';
9 const PLAN_DISPLAY_LABELS = {
10 'VIP Plan': 'VIP'
11 };
12 let lastInstance;
13
14 function tick() {
15 if (!window.MemberSpace) {
16 return setTimeout(tick, 100);
17 }
18 if (!window.FastCommentsUI) {
19 return setTimeout(tick, 100);
20 }
21 const target = document.getElementById('fastcomments-widget');
22 if (!target) {
23 return setTimeout(tick, 100);
24 }
25 const data = MemberSpace.getMemberInfo();
26 if (data.isLoggedIn && data.memberInfo) {
27 lastInstance = FastCommentsUI(target, {
28 tenantId: tenantId,
29 urlId: window.location.pathname,
30 simpleSSO: {
31 displayLabel: getDisplayLabel(data.memberInfo),
32 username: data.memberInfo.name,
33 email: data.memberInfo.email,
34 avatar: data.memberInfo.profileImageUrl
35 }
36 });
37 } else if (lastInstance) {
38 lastInstance.destroy();
39 lastInstance = FastCommentsUI(target, {
40 tenantId: tenantId,
41 urlId: window.location.pathname,
42 simpleSSO: getAnonSSOConfig()
43 });
44 }
45 }
46
47 function getAnonSSOConfig() {
48 if (ALLOW_ANON) {
49 return undefined;
50 }
51 return {
52 loginURL: LOGIN_URL
53 };
54 }
55
56 function getDisplayLabel(memberInfo) {
57 if (!memberInfo.memberships) {
58 return;
59 }
60 for (const membership of memberInfo.memberships) {
61 const label = PLAN_DISPLAY_LABELS[membership.name];
62 if (label) {
63 return label
64 }
65 }
66 }
67
68 tick();
69 })();
70</script>
71

When the user visits your site or application while logged in via MemberStack, they will automatically be logged into FastComments and their comments will be marked Verified.

Additionally, in the above example if you have a subscription plan called VIP Plan then we'll display a VIP badge next to the user's name. You can edit the example to add more plans. Reach out to support if you have questions.

Allow Anonymous Commenting

If you'd like to also have anonymous commenting, set ALLOW_ANON to true like this:

const ALLOW_ANON = true;

Also remember to change https://example.com/login to where you want users to go when they click the Login button:

This way users will have the option of entering their name and email to comment if they are not logged in to your member site.

Customization Internal Link

FastComments is designed to be customized to match your site.

If you'd like to add custom styling, or tweak configuration, Checkout our Customization Documentation to learn how.