Ok authentication is working but im not happy with variables/functions scope management