codeforbtv / baby-equipment-exchange

MIT License
0 stars 8 forks source link

Guard routes with a RouteGuard component and/or middleware #20

Open NathanWEdwards opened 1 year ago

NathanWEdwards commented 1 year ago

To minimize the amount of replicated code on pages and API routes for validating user authentication, a component that guards pages and routes, or a middleware, should be utilized.

JavaScript modules that employ a middleware design pattern NextAuth.js (soon to become Auth.js) and Passport.js offer convenient features to manage the request and response cycle of NodeJS applications in a few lines of code.

NathanWEdwards commented 10 months ago

Pull request 5 introduces a context for representing authentication states within the application. A feature branch protected-api-call has been created, and is introduced in Pull request 34. A higher-order client component, ProtectedComponent, wraps around components that require authentication.

Further effort is needed to encapsulate content within the ProtectedComponent and guard against unintential execution of code within a ProtectedComponent when pages are accessed without authorization.