Kavita/API/Middleware/UpdateUserAsActiveMiddleware.cs
Joe Milazzo 9f29fa593d
Progress Overhaul + Profile Page and a LOT more! (#4262)
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com>
Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
2025-12-09 10:00:11 -07:00

36 lines
926 B
C#

using System;
using System.Threading.Tasks;
using API.Data;
using API.Entities;
using API.Services.Store;
using Microsoft.AspNetCore.Http;
namespace API.Middleware;
/// <summary>
/// If the user is authenticated, will update the <see cref="AppUser.LastActive"/> field.
/// </summary>
/// <remarks>This should be last in the stack of middlewares</remarks>
/// <param name="next"></param>
public class UpdateUserAsActiveMiddleware(RequestDelegate next)
{
public async Task InvokeAsync(HttpContext context, IUserContext userContext, IUnitOfWork unitOfWork)
{
try
{
var userId = userContext.GetUserId();
if (userId > 0)
{
await unitOfWork.UserRepository.UpdateUserAsActive(userId.Value);
}
}
catch (Exception)
{
await next(context);
return;
}
await next(context);
}
}