Simple authentication system for Pages using Functions?

Is there a simple authentication system for Pages one can implement using Functions? I’m thinking one function to authenticate and another one to function as middleware to check for the presence of a cookie when requests are received for a particular path.

Does this help?

https://dev.to/charca/password-protection-for-cloudflare-pages-8ma