Move sync code to backend. Phase 1.
Auto init real-user primary email.
Support unregister.
Restore permission checks.
Minor edits.