Facade Design Pattern - SENG-350-2024-fall/Team-1 GitHub Wiki

Source: app/frontend/src/context/AuthContext.jsx, Lines 16-55.

The login function definied in the AuthProvider component acts as the Facade by providing a single interface for handling different login processes given a different userType.

const login = async (userType, credentials) => { ... }

The userType conditionals determine the correct endpoint and request body format. This abstraction allows the function to handle both staff and patient logins.

if (userType === "staff") { ... } else if (userType === "patient") { ... }

The Facade Design Pattern is effectively used in the AuthProvider component to streamline authentication by providing a simple, unified interface for both staff and patient login processes. The login function abstracts the complexity of handling different authentication requirements based on user type (staff or patient). By determining the correct API endpoint and request structure based on the userType, it hides the details of each login flow, allowing other parts of the application to initiate login without needing to manage the specifics. Using the Facade Pattern in this context results in cleaner, more maintainable code, making it an ideal choice for managing diverse authentication needs within a unified component.