store whole user in session actually
This commit is contained in:
parent
a30811cb84
commit
71584d91be
1 changed files with 14 additions and 17 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Femto.Api.Auth;
|
using Femto.Api.Auth;
|
||||||
using Femto.Modules.Auth.Application.Dto;
|
using Femto.Modules.Auth.Application.Dto;
|
||||||
|
|
||||||
|
@ -12,11 +14,10 @@ internal static class HttpContextSessionExtensions
|
||||||
CookieSettings cookieSettings
|
CookieSettings cookieSettings
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
var secure = cookieSettings.Secure;
|
var secure = cookieSettings.Secure;
|
||||||
var sameSite = cookieSettings.SameSite ? SameSiteMode.Strict : SameSiteMode.Unspecified;
|
var sameSite = cookieSettings.SameSite ? SameSiteMode.Strict : SameSiteMode.Unspecified;
|
||||||
var expires = session.Expires;
|
var expires = session.Expires;
|
||||||
|
|
||||||
httpContext.Response.Cookies.Append(
|
httpContext.Response.Cookies.Append(
|
||||||
"session",
|
"session",
|
||||||
session.SessionId,
|
session.SessionId,
|
||||||
|
@ -28,21 +29,17 @@ internal static class HttpContextSessionExtensions
|
||||||
Expires = expires,
|
Expires = expires,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
httpContext.Response.Cookies.Append(
|
httpContext.Response.Cookies.Append(
|
||||||
"uid",
|
"user",
|
||||||
user.Id.ToString(),
|
JsonSerializer.Serialize(
|
||||||
new CookieOptions
|
user,
|
||||||
{
|
new JsonSerializerOptions
|
||||||
Secure = cookieSettings.Secure,
|
{
|
||||||
SameSite = cookieSettings.SameSite ? SameSiteMode.Strict : SameSiteMode.Unspecified,
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||||
Expires = session.Expires,
|
Converters = { new JsonStringEnumConverter() },
|
||||||
}
|
}
|
||||||
);
|
),
|
||||||
|
|
||||||
httpContext.Response.Cookies.Append(
|
|
||||||
"uname",
|
|
||||||
user.Username,
|
|
||||||
new CookieOptions
|
new CookieOptions
|
||||||
{
|
{
|
||||||
Secure = cookieSettings.Secure,
|
Secure = cookieSettings.Secure,
|
||||||
|
@ -55,6 +52,6 @@ internal static class HttpContextSessionExtensions
|
||||||
public static void DeleteSession(this HttpContext httpContext)
|
public static void DeleteSession(this HttpContext httpContext)
|
||||||
{
|
{
|
||||||
httpContext.Response.Cookies.Delete("session");
|
httpContext.Response.Cookies.Delete("session");
|
||||||
httpContext.Response.Cookies.Delete("hasSession");
|
httpContext.Response.Cookies.Delete("user");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue