refactor: use this in static method

This commit is contained in:
Polianin Nikita 2024-08-10 23:11:43 +03:00
parent c51a9cecc9
commit b1250616a7
3 changed files with 7 additions and 3 deletions

View File

@ -6,7 +6,7 @@ namespace Mirea.Api.Endpoint.Common.Services;
public static class UrlHelper public static class UrlHelper
{ {
public static string CurrentDomain(HttpContext context) => public static string GetCurrentDomain(this HttpContext context) =>
context.Request.Headers["X-Forwarded-Host"].FirstOrDefault() ?? context.Request.Host.Host; context.Request.Headers["X-Forwarded-Host"].FirstOrDefault() ?? context.Request.Host.Host;
private static string CreateSubPath(string? path) private static string CreateSubPath(string? path)

View File

@ -74,9 +74,11 @@ public partial class SetupController(
Response.Cookies.Append("AuthToken", token, new CookieOptions Response.Cookies.Append("AuthToken", token, new CookieOptions
{ {
Path = UrlHelper.GetSubPathWithoutFirstApiName + "api", Path = UrlHelper.GetSubPathWithoutFirstApiName + "api",
Domain = UrlHelper.CurrentDomain(ControllerContext.HttpContext), Domain = HttpContext.GetCurrentDomain(),
#if !DEBUG
Secure = true, Secure = true,
HttpOnly = true HttpOnly = true
#endif
}); });
return Ok(true); return Ok(true);
} }

View File

@ -30,9 +30,11 @@ public class AuthController(IOptionsSnapshot<Admin> user, AuthService auth, Pass
{ {
Expires = expires, Expires = expires,
Path = UrlHelper.GetSubPathWithoutFirstApiName + "api", Path = UrlHelper.GetSubPathWithoutFirstApiName + "api",
Domain = UrlHelper.CurrentDomain(ControllerContext.HttpContext), Domain = HttpContext.GetCurrentDomain(),
#if !DEBUG
Secure = true, Secure = true,
HttpOnly = true HttpOnly = true
#endif
}; };
Response.Cookies.Append(name, value, cookieOptions); Response.Cookies.Append(name, value, cookieOptions);