I’ve been trying to implement a redirect after sign-in that takes the user back to the original page they were viewing before authentication. However, the user is consistently redirected to the profile page instead.
<div class="alert alert-danger text-center justify-content-center align-items-center" role="alert"
style="margin: 0 auto; color: red;">
<a id="loginLink" href="#"><b>"Click Here TO LOGIN"</b></a>
</div>
<script>
function updateLoginLink() {
try {
var currentUrl = window.location.pathname + window.location.search;
var encodedCurrentUrl = encodeURIComponent(currentUrl);
var signInUrl = "/SignIn?returnUrl=" + encodedCurrentUrl;
var loginLink = document.getElementById('loginLink');
if (loginLink) {
loginLink.href = signInUrl;
} else {
console.error('Login link element not found!');
}
} catch (error) {
console.error('An error occurred while setting the login link:', error);
}
}
document.addEventListener('DOMContentLoaded', function () {
var loginLink = document.getElementById('loginLink');
if (loginLink) {
loginLink.addEventListener('click', function (event) {
event.preventDefault();
updateLoginLink();
window.location.href = loginLink.href;
});
}
});
</script>