refine auth module and sql query