add login function and middleware and cookie