improve the redirect logic, should remember the url before auth