refactor(app) AI refactoring before moving to Lab3 done

This commit is contained in:
imadev
2026-10-26 19:39:45 +03:00
parent d14fed291e
commit 71174f844c
30 changed files with 895 additions and 560 deletions
+4 -6
View File
@@ -65,8 +65,8 @@ func (h *Handler) CreateSession(c fiber.Ctx) error {
// RevokeSession deletes the current token. The middleware has already proven
// that the token exists, so a repeated DELETE is a 401, not a 204.
func (h *Handler) RevokeSession(c fiber.Ctx) error {
token, _ := c.Locals(sessionTokenLocal).(string)
if token == "" {
token, ok := common.SessionToken(c)
if !ok {
return common.SendChallenge(c, bearerChallenge, "authentication required")
}
@@ -79,8 +79,6 @@ func (h *Handler) RevokeSession(c fiber.Ctx) error {
return c.SendStatus(fiber.StatusNoContent)
}
const sessionTokenLocal = "sessionToken"
// BearerAuth accepts only an opaque Bearer token. X-User-Id is deliberately
// never read: with lab 2 it can neither create nor override an identity.
func BearerAuth(sessions *session.Store) fiber.Handler {
@@ -104,8 +102,8 @@ func BearerAuth(sessions *session.Store) fiber.Handler {
common.ErrorCodeUnavailable, "session store unavailable")
}
c.Locals("userID", userID)
c.Locals(sessionTokenLocal, token)
c.Locals(common.KeyUserID, userID)
c.Locals(common.KeySessionToken, token)
return c.Next()
}
}