Phase 3 Week 7: Fix device auth middleware to set device object
- Update device auth middleware to set actual device object - Change from DeviceContext to database.Devices - Fix RequirePermission to use database.Devices - Ensures handlers can access full device information - Required for KOReader sync handlers to function properly
This commit is contained in:
@@ -98,7 +98,8 @@ func (m *DeviceAuthMiddleware) Authenticate(next echo.HandlerFunc) echo.HandlerF
|
|||||||
AutoSync: device.AutoSync.Bool && device.AutoSync.Valid,
|
AutoSync: device.AutoSync.Bool && device.AutoSync.Valid,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Set("device", ctx)
|
c.Set("device", device)
|
||||||
|
c.Set("device_ctx", ctx)
|
||||||
c.Set("device_id", device.ID.Bytes)
|
c.Set("device_id", device.ID.Bytes)
|
||||||
c.Set("user_id", device.UserID.Bytes)
|
c.Set("user_id", device.UserID.Bytes)
|
||||||
|
|
||||||
@@ -119,7 +120,7 @@ func (m *DeviceAuthMiddleware) getRequestType(path string) string {
|
|||||||
func (m *DeviceAuthMiddleware) RequirePermission(permission string) echo.MiddlewareFunc {
|
func (m *DeviceAuthMiddleware) RequirePermission(permission string) echo.MiddlewareFunc {
|
||||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
device, ok := c.Get("device").(DeviceContext)
|
device, ok := c.Get("device").(database.Devices)
|
||||||
if !ok {
|
if !ok {
|
||||||
return c.JSON(http.StatusUnauthorized, map[string]string{
|
return c.JSON(http.StatusUnauthorized, map[string]string{
|
||||||
"error": "device not authenticated",
|
"error": "device not authenticated",
|
||||||
|
|||||||
Reference in New Issue
Block a user