feat: migrate snowflake ids and refresh migrations
This commit is contained in:
@@ -9,20 +9,20 @@ namespace TakeoutSaaS.Shared.Web.Security;
|
||||
public static class ClaimsPrincipalExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取当前用户 Id(不存在时返回 Guid.Empty)
|
||||
/// 获取当前用户 Id(不存在时返回 0)。
|
||||
/// </summary>
|
||||
public static Guid GetUserId(this ClaimsPrincipal? principal)
|
||||
public static long GetUserId(this ClaimsPrincipal? principal)
|
||||
{
|
||||
if (principal == null)
|
||||
{
|
||||
return Guid.Empty;
|
||||
return 0;
|
||||
}
|
||||
|
||||
var identifier = principal.FindFirstValue(ClaimTypes.NameIdentifier)
|
||||
?? principal.FindFirstValue("sub");
|
||||
|
||||
return Guid.TryParse(identifier, out var userId)
|
||||
return long.TryParse(identifier, out var userId)
|
||||
? userId
|
||||
: Guid.Empty;
|
||||
: 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user