I have the following situation.
When the user accesses the site: www.site.com.br I check if there exists the parameter sc = 2 at the end of the URL, if it exists it can access the site, if it exists it is redirected to www .site.com.br / system / 401
On this page www.site.com.br/sistema/401 I saved the page where the user came from:
var ref = document.referrer
On that same page I have a form that the user enters his email to "login". After inserting the email it is redirected to the page it was before through the code below and I enter the sc = 2 parameter at the end of the url:
window.location.href = ref + (/\?.{1,}=/.test(ref)? '&': '?') + 'sc = 2';
But imagine that the user accesses the page directly: www.site.com.br/sistema/401 ie this will be the page that will be saved in the document.referrer there when the person logs in it will be redirected for that same page and the user will be in infinite loop trying to login.
How would I check to see if the document.referrer matches a specific page, it would have another URL? EX:
var ref = document.referrer;
if (ref == 'https://www.site.com.br/Sistema/401'){ ref = 'https://www.site.com.br'; }
window.location.href = ref + (/\?.{1,}=/.test(ref) ? '&' : '?') + 'sc=2';
I tried to do the above but did not work where I went wrong? In case when the user logs in:
it should be directed to:
But that's not what happens, it's still being redirected to link