Conversation
Detailed analysis: 401 error in handleAuthFailure was forcing redirect even on public routes. Also cleaned up redundant encodeURIComponent in proxy.ts.
❌ Deploy Preview for ornate-blancmange-89db6b failed. Why did it fail? →
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the application's authentication flow by resolving an infinite redirect loop on public routes and fixing a double encoding issue in redirect URLs. The changes refine how the authentication proxy and client-side failure handling interact with public and protected paths, leading to a more robust and user-friendly authentication experience. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
| const isPublicPath = | ||
| pathname === '/' || | ||
| pathname === ROUTES.AUTH || | ||
| pathname.startsWith('/auth/') || | ||
| pathname.startsWith('/blog/') || | ||
| pathname.startsWith('/share/'); |
There was a problem hiding this comment.
这部分用于判断公共路径的逻辑与 apps/DocFlow/src/proxy.ts 中的 isPublicRoute 函数存在重复。
代码重复会增加维护成本,并且两边的逻辑存在不一致:
proxy.ts中的逻辑更完整,它通过PUBLIC_ROUTES集合处理了像/blog和/share这样的精确匹配路径,而此处的逻辑只处理了带斜杠的子路径前缀(例如/blog/),可能会漏掉对/blog页面的判断。- 未来如果需要修改公共路径的定义,需要在两个地方同步修改,容易遗漏。
建议:
将 proxy.ts 中的 PUBLIC_ROUTES 常量和 isPublicRoute 函数提取到一个公共的、与 Edge runtime 兼容的文件中(例如 src/utils/routes.ts 或 src/utils/auth.ts),然后在 proxy.ts 和 client.ts 中都导入并使用这个共享函数。
这样可以确保逻辑统一,并简化未来的维护工作。例如,在 client.ts 中可以这样使用:
import { isPublicRoute } from '@/utils/routes'; // 假设的路径
// ... in handleAuthFailure()
if (isPublicRoute(pathname)) return;
PR 描述
PR 类型
Issue 关联
Closes #
其他信息