separated authentication function from router