epic-stack
epic-stack copied to clipboard
Upgrade react router and add auth middleware
Summary
This PR upgrades React Router to version 7.9.0 and implements its new middleware feature for authentication. This change centralizes requireUser and requireAnonymous checks into dedicated middleware functions, replacing scattered direct calls in various routes.
Key changes include:
- Upgrading all
@react-router/*andreact-routerpackages. - Enabling the
v8_middlewarefeature flag. - Introducing
app/middleware.server.tswithrequireUserMiddlewareandrequireAnonymousMiddleware. - Updating
settings+/profile.tsxto userequireUserMiddleware. - Updating
_auth+/login.tsx,_auth+/signup.tsx,_auth+/onboarding.tsx,_auth+/onboarding_.$provider.tsx, and_auth+/reset-password.tsxto userequireAnonymousMiddleware. - Adjusting
server/index.tsto provide theRouterContextProviderfor middleware context. - Updating
_seo+/sitemap[.]xml.tsto read the build from the new context. - Updating
_auth+/auth.$provider.callback.test.tsto pass the correct context type. - Minor type cleanup in
users+/index.tsx.
Test Plan
- Verify Login/Logout:
- Navigate to
/loginand successfully log in. - Navigate to
/settings/profile(should be accessible). - Log out.
- Navigate to
- Verify Signup/Onboarding:
- Navigate to
/signupand successfully create a new account, completing the onboarding flow. - Navigate to
/settings/profile(should be accessible). - Log out.
- Navigate to
- Verify Protected Routes (Logged Out):
- While logged out, try to access
/settings/profile. You should be redirected to/login.
- While logged out, try to access
- Verify Anonymous Routes (Logged In):
- While logged in, try to access
/loginor/signup. You should be redirected to/.
- While logged in, try to access
- Verify Reset Password Flow:
- Initiate and complete a password reset flow.
- Verify Sitemap:
- Navigate to
/sitemap.xmland ensure it loads without errors.
- Navigate to
- Run Tests:
- Execute
npm testto ensure all existing tests pass.
- Execute
Checklist
- [x] Tests updated
- [ ] Docs updated