Skip to content

Commit

Permalink
fix(gomall/tutorial):ch09 redirect status
Browse files Browse the repository at this point in the history
  • Loading branch information
baiyutang committed Jun 1, 2024
1 parent b788321 commit c5acdb7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Login(ctx context.Context, c *app.RequestContext) {
utils.SendErrResponse(ctx, c, consts.StatusOK, err)
return
}
c.Redirect(consts.StatusOK, []byte(redirect))
c.Redirect(consts.StatusFound, []byte(redirect))
}

// Register .
Expand All @@ -60,7 +60,7 @@ func Register(ctx context.Context, c *app.RequestContext) {
utils.SendErrResponse(ctx, c, consts.StatusOK, err)
return
}
c.Redirect(consts.StatusOK, []byte("/"))
c.Redirect(consts.StatusFound, []byte("/"))
}

// Logout .
Expand All @@ -80,5 +80,5 @@ func Logout(ctx context.Context, c *app.RequestContext) {
utils.SendErrResponse(ctx, c, consts.StatusOK, err)
return
}
c.Redirect(consts.StatusOK, []byte("/"))
c.Redirect(consts.StatusFound, []byte("/"))
}
3 changes: 2 additions & 1 deletion gomall/tutorial/ch09/app/frontend/middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

frontendUtils "github.com/cloudwego/biz-demo/gomall/app/frontend/utils"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/protocol/consts"
"github.com/hertz-contrib/sessions"
)

Expand All @@ -35,7 +36,7 @@ func Auth() app.HandlerFunc {
s := sessions.Default(c)
userId := s.Get("user_id")
if userId == nil {
c.Redirect(302, []byte("/sign-in?next="+c.FullPath()))
c.Redirect(consts.StatusFound, []byte("/sign-in?next="+c.FullPath()))
c.Abort()
return
}
Expand Down

0 comments on commit c5acdb7

Please sign in to comment.