feat: log user id

This commit is contained in:
CalciumIon
2024-08-04 14:35:16 +08:00
parent a0a3807bd4
commit 67878731fc
2 changed files with 11 additions and 5 deletions

View File

@@ -143,6 +143,12 @@ func TokenAuth() func(c *gin.Context) {
key = parts[0]
}
token, err := model.ValidateUserToken(key)
if token != nil {
id := c.GetInt("id")
if id == 0 {
c.Set("id", token.Id)
}
}
if err != nil {
abortWithOpenAiMessage(c, http.StatusUnauthorized, err.Error())
return