Toast Message after successful signed in

Hello,I want to show a Toast message after user login. For this i put the below codes on Other->Login Page->User_LoggedIn:

function User_LoggedIn($usr)
{
    //Log("User Logged In");

    echo '<script>
        const Toast = Swal.mixin({
  toast: true,
  position: "top-end",
  showConfirmButton: false,
  timer: 3000,
  timerProgressBar: true,
  didOpen: (toast) => {
    toast.onmouseenter = Swal.stopTimer;
    toast.onmouseleave = Swal.resumeTimer;
  }
});
Toast.fire({
  icon: "success",
  title: "Signed in successfully"
});
    </script>';

}

This code is not showing message after user login. Did i put the code on right event? Experts please suggest me if any mistake in the coding?Thanks in advance.

You should not put Javascript code in Server Events section.If you want to just display your custom message, you may simply put this following code in that User_LoggedIn server event:

$this->setSuccessMessage("Signed in successfully.");

Also check your advanced setting Use Bootstrap Toast message.

Hello,Use Bootstrap Toast message option is enable and $this->setSuccessMessage(“Signed in successfully.”); also showing message. But Toast with sweetalert2 mix is more graphical thats why if possible i wanted to use this in my project. I saw a post on this forum which is relevant to my expectation. Discussion link is : https://discourse.hkvstore.com/t/how-to-add-toast-message-on-successful-login/5026/4 tried the below code on Server Events → Page Foot. No error is showing but message is also not appearing:

if (isset($_SESSION['success_login'])) {
echo '<script>
function showtoasterlogin(){
        const Toast = Swal.mixin({
  toast: true,
  position: "top-end",
  showConfirmButton: false,
  timer: 3000,
  timerProgressBar: true,
  didOpen: (toast) => {
    toast.onmouseenter = Swal.stopTimer;
    toast.onmouseleave = Swal.resumeTimer;
  }
});
Toast.fire({
  icon: "success",
  title: "Signed in successfully"
});
}
window.onload = showtoasterlogin;
</script>';
 }

Any idea how can i do this?

  1. There is no $_SESSION[‘success_login’] unless you set it somewhere yourself.
  2. You better use the “toast” event to open your own toast, e.g.
$(document).on("toast", (args) => {
	// console.log(args); // View the args first and see what you can use
	args.show = false; // Disable the default toast
	// your own code to open your own toast using the info from args
	// ...
});