File tree Expand file tree Collapse file tree
src/main/java/com/involutionhell/backend/usercenter/controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,9 +69,18 @@ public void renderAuth(HttpServletResponse response) throws IOException {
6969 * GitHub → localhost:3000/api/auth/callback/github → Next.js rewrite → localhost:8080/api/auth/callback/github
7070 */
7171 @ GetMapping ("/api/auth/callback/github" )
72- public void login (@ RequestParam String code ,
73- @ RequestParam String state ,
72+ public void login (@ RequestParam ( required = false ) String code ,
73+ @ RequestParam ( required = false ) String state ,
7474 HttpServletResponse response ) throws IOException {
75+ // 参数缺失时直接走失败分支:若 @RequestParam 保持 required=true,Spring 在进入方法前
76+ // 就抛 MissingServletRequestParameterException → 默认 500 白屏;
77+ // 手动 null check 能把 "用户直接访问 / GitHub 异常回调" 统一兜底到前端错误页。
78+ if (code == null || state == null ) {
79+ log .warn ("[OAuth] GitHub callback missing code/state (direct access?), redirecting to error page" );
80+ response .sendRedirect (frontEndUrl + "/login?error=oauth_failed" );
81+ return ;
82+ }
83+
7584 AuthCallback callback = new AuthCallback ();
7685 callback .setCode (code );
7786 callback .setState (state );
You can’t perform that action at this time.
0 commit comments