mirror of
https://github.com/hazemKrimi/crimson-vault.git
synced 2026-05-01 18:20:27 +00:00
chore: custom error handler with automatic logging
This commit is contained in:
@@ -18,25 +18,25 @@ func (api *API) AuthSessionMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
sess, err := session.Get("session", context)
|
||||
|
||||
if err != nil || sess.IsNew {
|
||||
return context.String(http.StatusUnauthorized, "User not authenticated!")
|
||||
return types.Error{Code: http.StatusUnauthorized, Messages: []string{"User not authenticated!"}}
|
||||
}
|
||||
|
||||
id, ok := sess.Values["sessionId"].(string)
|
||||
|
||||
if !ok || id == "" {
|
||||
return context.String(http.StatusUnauthorized, "User not authenticated!")
|
||||
return types.Error{Code: http.StatusUnauthorized, Messages: []string{"User not authenticated!"}}
|
||||
}
|
||||
|
||||
sessionId, err := uuid.Parse(id)
|
||||
|
||||
if err != nil {
|
||||
return context.String(http.StatusUnauthorized, "User not authenticated!")
|
||||
return types.Error{Code: http.StatusUnauthorized, Messages: []string{"User not authenticated!"}}
|
||||
}
|
||||
|
||||
var user types.User
|
||||
|
||||
if err := api.db.GetUserBySessionId(sessionId, &user); err != nil {
|
||||
return context.String(http.StatusUnauthorized, "User not authenticated!")
|
||||
return types.Error{Code: http.StatusUnauthorized, Messages: []string{"User not authenticated!"}}
|
||||
}
|
||||
|
||||
context.Set("id", sess.Values["id"])
|
||||
|
||||
Reference in New Issue
Block a user