Programmatically logout the user

In the following threads are examples

I suppose you wanna do something like

some node in Node-RED -> msg -> ui template -> extract msg.payload -> call a javascript function to do some stuff
or
some node in Node-RED -> msg -> template node with your html/javascript code -> extract msg.payload -> call a javascript function to do some stuff

It's unclear how your architecture looks like so best is you provide your flow "as is" and we can look at it and give further advice.