chore: ignore password for get current user

This commit is contained in:
Noah Hsu
2022-06-26 16:55:37 +08:00
parent 7cbfe93a02
commit acd4083399
4 changed files with 11 additions and 3 deletions

View File

@ -60,5 +60,6 @@ func Login(c *gin.Context) {
// if token is empty, return guest user
func CurrentUser(c *gin.Context) {
user := c.MustGet("user").(*model.User)
user.Password = ""
common.SuccessResp(c, gin.H{"user": user})
}

View File

@ -11,7 +11,12 @@ import (
func Auth(c *gin.Context) {
token := c.GetHeader("Authorization")
if token == "" {
guest, _ := db.GetGuest()
guest, err := db.GetGuest()
if err != nil {
common.ErrorResp(c, err, 500, true)
c.Abort()
return
}
c.Set("user", guest)
c.Next()
return