You can, but it is pointless once your eyes are closed. Glasses only filter light that reaches your eyes, so wearing them while you actually sleep does nothing. They are harmless if you doze off in them, just not doing any real work during the nap itself.
The value comes before the nap. If you are winding down in a bright room or coming off screens, an amber Night lens for the twenty or thirty minutes beforehand helps signal rest. Put them on to prepare for sleep, then take them off once you are out.