How can I mix two materials based on incoming light
I have made a little shader that does this. See below for the node setup and a test render.

First there are two shaders, one for the ground (green-brown-noise) and one for the glowing city lights.

Second, there is a mask for the city lights that makes them appear as spots.

Third, and this is answering your question, a value calculated as the dot product between the normal of the planet surface and the vector from the light source to the planet. Very simplified, dot product does this: If they point in the same direction, the dot product will be 1. If they point in opposite direction, dot product is 0. It was a loong time since I studied linear algebra so don't sue me over this.

Fourth, the second mask is multiplied with the third and this is fed as a factor into the mix node that mixes the two materials (land vs city lights).

Node setup. Note how I had to manually calculate the vector for the dot product. In this case (my planet is at 0, 0, 0) it is only the negative value of the light source position.



Test render: