package web import ( "videoweb/app/service/authser" "github.com/gin-gonic/gin" ) // AbortSSRIfSessionExpired 处理 SSR 场景下的会话失效码。 // aborted=true:已跳转登录,调用方应立刻 return; // retry=true:游客已重新登录,调用方应重试上游请求。 func AbortSSRIfSessionExpired(c *gin.Context, code int) (aborted, retry bool) { if !authser.IsSessionExpiredCode(code) { return false, false } retry, needLogin := authser.OnSessionExpired(c, code) if needLogin { RedirectToLogin(c) return true, false } return false, retry } // TryJSONSessionRecover JSON 接口遇到会话失效时:游客重登后返回 true(应重试); // 注册账号清 cookie 后返回 false,调用方继续把 code=1000 交给前端弹登录。 func TryJSONSessionRecover(c *gin.Context, code int) bool { if !authser.IsSessionExpiredCode(code) { return false } retry, _ := authser.OnSessionExpired(c, code) return retry }