refact(server): refactor the xsrf function to be cleaner for the book