using Tango.Portal.Chat.Web.Models; namespace Tango.Portal.Chat.Web.Utils { public class SessionUtils { public static void SetSessionUser(HttpContext context, SessionUser user) { if (context == null) throw new ArgumentNullException(nameof(context)); if (user == null) throw new ArgumentNullException(nameof(user)); var json = System.Text.Json.JsonSerializer.Serialize(user); context.Session.SetString("SessionUser", json); } public static SessionUser? GetSessionUser(HttpContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); var json = context.Session.GetString("SessionUser"); if (string.IsNullOrWhiteSpace(json)) { return null; } return System.Text.Json.JsonSerializer.Deserialize(json); } public static bool IsUserAuthenticated(HttpContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); var user = GetSessionUser(context); return user != null; } } }