User Ban Message

Display a custom message when a banned user tries to log in

Through the moderation console, content moderators have the option to issue a ban to a user to prevent them from engaging in conversations or even from logging into Viafoura.

When issuing a ban, through the moderation console, there is an option to include a custom message that can be shown to banned users when they try to log in.

While this message is shown by default to users when using our Viafoura in-house authentication with tray, this message can also be retrieved and displayed to users using Viafoura Javascript API and the errorContext function.

Below is an example of the errorcontext returned for a temporarily banned user (note the value of isPermanent):
endDate: 1548774167000
error_key: "login_banned"
isPermanent: 0
reason: "message to user"

Below an example of the errorcontext returned for a temporarily banned user (note the value of isPermanent):
endDate: 1489499284000
error_key: "login_banned"
isPermanent: 1
reason: "message to user"

📘

Additional information regarding the value of "endDate"

  1. The endDate of a temporary ban is included in the errorContext. It can be displayed as a date or calculated into a countdown.
  2. Since by definition permanent bans don't have an endDate, the date returned in errorContext matches the date the ban was issued.

Code sample

Below is an example code sample intended to be used as a potential option for implementation. You can customize the code and behaviour to your specific needs, and we highly recommend customizing the prompts to match your brand voice and UX.

window.vf.$subscribe('login', 'failure', function(errorContext) {
        if (errorContext.error_key == 'login_banned' && errorContext.isPermanent == '1') { 
                alert('Permanent ban: ' + errorContext.reason)
                console.log(errorContext.reason);
        } 
        else if (errorContext.error_key == 'login_banned' && errorContext.isPermanent == '0') {
                alert('Banned until: ' + errorContext.endDate + 'because of:' + errorContext.reason)
                console.log(errorContext.reason);
                }
        else {
                console.log(errorContext.reason);
        }
    });