Adding authentication check and DB switching