From 71584d91bef074c3867927e85d96ab7b856d4c6f Mon Sep 17 00:00:00 2001 From: john Date: Tue, 20 May 2025 10:06:56 +0200 Subject: [PATCH] store whole user in session actually --- .../Sessions/HttpContextSessionExtensions.cs | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Femto.Api/Sessions/HttpContextSessionExtensions.cs b/Femto.Api/Sessions/HttpContextSessionExtensions.cs index 4de3e92..865467e 100644 --- a/Femto.Api/Sessions/HttpContextSessionExtensions.cs +++ b/Femto.Api/Sessions/HttpContextSessionExtensions.cs @@ -1,3 +1,5 @@ +using System.Text.Json; +using System.Text.Json.Serialization; using Femto.Api.Auth; using Femto.Modules.Auth.Application.Dto; @@ -12,11 +14,10 @@ internal static class HttpContextSessionExtensions CookieSettings cookieSettings ) { - var secure = cookieSettings.Secure; var sameSite = cookieSettings.SameSite ? SameSiteMode.Strict : SameSiteMode.Unspecified; var expires = session.Expires; - + httpContext.Response.Cookies.Append( "session", session.SessionId, @@ -28,21 +29,17 @@ internal static class HttpContextSessionExtensions Expires = expires, } ); - + httpContext.Response.Cookies.Append( - "uid", - user.Id.ToString(), - new CookieOptions - { - Secure = cookieSettings.Secure, - SameSite = cookieSettings.SameSite ? SameSiteMode.Strict : SameSiteMode.Unspecified, - Expires = session.Expires, - } - ); - - httpContext.Response.Cookies.Append( - "uname", - user.Username, + "user", + JsonSerializer.Serialize( + user, + new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + Converters = { new JsonStringEnumConverter() }, + } + ), new CookieOptions { Secure = cookieSettings.Secure, @@ -55,6 +52,6 @@ internal static class HttpContextSessionExtensions public static void DeleteSession(this HttpContext httpContext) { httpContext.Response.Cookies.Delete("session"); - httpContext.Response.Cookies.Delete("hasSession"); + httpContext.Response.Cookies.Delete("user"); } }