You should consider using tools like Keycloak (https://www.keycloak.org) to be inserted on top of Joomla and Moodle and connecting them to it by using OIDC or SAML (moodle has these client protocols embedded in core and you can use miniorange in joomla). No dependencies between the two webapp, a new "node" which manage the authentication/authorization.