Files
drive/apps/backend/internal/reqctx/reqctx.go

68 lines
2.1 KiB
Go
Raw Normal View History

package reqctx
import (
"errors"
"github.com/gofiber/fiber/v2"
)
const authenticatedUserKey = "authenticatedUser"
2025-12-27 19:27:08 +00:00
const vfsAccessScope = "vfsAccessScope"
const currentAccountKey = "currentAccount"
2026-01-01 18:29:52 +00:00
const currentDriveKey = "currentDrive"
const currentOrganizationKey = "currentOrganization"
var ErrUnauthenticatedRequest = errors.New("unauthenticated request")
// AuthenticatedUser returns the authenticated user from the given fiber context.
// Returns ErrUnauthenticatedRequest if not authenticated.
// The caller must type assert the returned value to the appropriate user type.
func AuthenticatedUser(c *fiber.Ctx) any {
return c.Locals(authenticatedUserKey)
}
// SetAuthenticatedUser sets the authenticated user in the fiber context.
2025-12-27 19:27:08 +00:00
func SetAuthenticatedUser(c *fiber.Ctx, user any) {
c.Locals(authenticatedUserKey, user)
}
2025-12-27 19:27:08 +00:00
// SetCurrentAccount sets the current account in the fiber context.
func SetCurrentAccount(c *fiber.Ctx, account any) {
c.Locals(currentAccountKey, account)
}
2026-01-01 18:29:52 +00:00
// SetCurrentDrive sets the current drive in the fiber context.
func SetCurrentDrive(c *fiber.Ctx, drive any) {
c.Locals(currentDriveKey, drive)
}
2025-12-27 19:27:08 +00:00
// SetVFSAccessScope sets the VFS access scope in the fiber context.
func SetVFSAccessScope(c *fiber.Ctx, scope any) {
c.Locals(vfsAccessScope, scope)
}
// SetCurrentOrganization sets the current organization in the fiber context.
func SetCurrentOrganization(c *fiber.Ctx, organization any) {
c.Locals(currentOrganizationKey, organization)
}
2025-12-27 19:27:08 +00:00
// CurrentAccount returns the current account from the given fiber context.
func CurrentAccount(c *fiber.Ctx) any {
return c.Locals(currentAccountKey)
}
2026-01-01 18:29:52 +00:00
// CurrentDrive returns the current drive from the given fiber context.
func CurrentDrive(c *fiber.Ctx) any {
return c.Locals(currentDriveKey)
}
// CurrentOrganization returns the current organization from the given fiber context.
func CurrentOrganization(c *fiber.Ctx) any {
return c.Locals(currentOrganizationKey)
}
2025-12-27 19:27:08 +00:00
// VFSAccessScope returns the VFS access scope from the given fiber context.
func VFSAccessScope(c *fiber.Ctx) any {
return c.Locals(vfsAccessScope)
}