Moved ajax authentication logic from ajax to sync.