How to properly login with database connection in a SPA?