🛡️Get Started
Let's protect your website with nonstress!
Add Script Tag
Add this tag to your website's html to use nonstress in the page.
<script src="https://hamutan86.pythonanywhere.com/nonstress/nonstress.js" async defer></script><script src="https://hamutan86.pythonanywhere.com/nonstress/nonstress.js" async defer></script>
Now your page is prepared to being protected by nonstress!
Get The Token
You need "token" to check request's validity on server side. the token will be created automatically when the user opened your page.
When the token is ready, nonstressCompleted
Event will be dispatched.
Seeing is believing, check this example code:
document.addEventListener("nonstressCompleted", (e) => {
console.log(e.detail.success); // true|false
console.log(e.detail.token); // "0dc240c66802f7329a1cb9f85804c49f6bb34a..."
});
When e.detail.success
was false, it means failed to verify the user.
In that case, you can't get token. so you have to reload the page, or use nonstress.generateToken() .
You can get the token directly even the Event is already dispatched:
nonstress.getToken(); // "0dc240c66802f7329a1cb9f85804c49f6bb34a..."
It's pretty simple. in this case, it returns empty string when nonstress isn't completed or it's failed.
Regenerate The Token
Oh, user typo the password, cancelled action, or nonstress failed? if token is once validated, it can't be reused, but you don't have to reload the page.
Here's magic:
nonstress.generateToken()
It will regenerate the token, redispatch the Event and overwrite nonstress.getToken() .
Last updated