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.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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue