Fix a bug when the database is deleted while a user is logged in.