bugfixing refresh token
This commit is contained in:
@@ -41,11 +41,12 @@ func (store *Store) CheckToken(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userID, ok := (*claims)["id"].(uint)
|
userIDF, ok := (*claims)["id"].(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.JSON(401, gin.H{"error": "claims does not contain id"})
|
ctx.JSON(401, gin.H{"error": "claims does not contain id"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
userID := uint(userIDF)
|
||||||
|
|
||||||
user := models.User{Model: gorm.Model{ID: userID}}
|
user := models.User{Model: gorm.Model{ID: userID}}
|
||||||
tx := store.DB.First(&user)
|
tx := store.DB.First(&user)
|
||||||
@@ -71,11 +72,12 @@ func (store *Store) RefreshToken(ctx *gin.Context) {
|
|||||||
|
|
||||||
fmt.Printf("claims: %v\n", claims)
|
fmt.Printf("claims: %v\n", claims)
|
||||||
|
|
||||||
userID, ok := (*claims)["id"].(uint)
|
userIDF, ok := (*claims)["id"].(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "invalid token claims"})
|
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "invalid token claims"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
userID := uint(userIDF)
|
||||||
|
|
||||||
user := models.User{}
|
user := models.User{}
|
||||||
tx := store.DB.First(&user, userID)
|
tx := store.DB.First(&user, userID)
|
||||||
|
|||||||
@@ -90,11 +90,12 @@ func (store *Store) UpdateUser(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userID, ok := (*claims)["id"].(uint)
|
userIDF, ok := (*claims)["id"].(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "invalid user id in claims"})
|
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "invalid user id in claims"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
userID := uint(userIDF)
|
||||||
|
|
||||||
var user models.User
|
var user models.User
|
||||||
if err := store.DB.First(&user, userID).Error; err != nil {
|
if err := store.DB.First(&user, userID).Error; err != nil {
|
||||||
@@ -118,11 +119,12 @@ func (store *Store) DeleteUser(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userID, ok := (*claims)["id"].(uint)
|
userIDF, ok := (*claims)["id"].(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "invalid user id in claims"})
|
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "invalid user id in claims"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
userID := uint(userIDF)
|
||||||
|
|
||||||
var user models.User
|
var user models.User
|
||||||
if err := store.DB.First(&user, userID).Error; err != nil {
|
if err := store.DB.First(&user, userID).Error; err != nil {
|
||||||
@@ -131,5 +133,5 @@ func (store *Store) DeleteUser(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
store.DB.Delete(&user)
|
store.DB.Delete(&user)
|
||||||
ctx.JSON(http.StatusOK, user)
|
ctx.JSON(http.StatusOK, user)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user