Your ideia seems good, see this little pseudo-code and tell me if this is the way:
-- server.lua
function onTryLogin(login, password)
-- check login and password code
triggerClientEvent("onLoginReturnState", getRootElement(), return_code)
end
addEvent, bla bla bla
-- client.lua
coroutine_handle = 0
function onLoginReturnState(return_code)
coroutine.resume(coroutine_handle, return_code)
end
function onButtonLoginClick()
-- assume this is a coroutine created somewhere when the button is clicked
-- bla bla bla
triggerServerEvent("onTryLogin", bla bla bla)
exit_code = coroutine.yield()
-- check exit code etc
end
addEvent bla bla bla