C# gw offload work, schema-izing stuff

This commit is contained in:
Rory&
2026-02-06 05:21:31 +01:00
parent 3a5009f7c7
commit 862bfd7803
25 changed files with 817 additions and 83 deletions

View File

@@ -46,4 +46,15 @@ public class SpacebarAuthenticationService(ILogger<SpacebarAuthenticationService
},
config.AuthCacheExpiry);
}
public async Task<User> GetCurrentSessionAsync(string token) {
var res = await ValidateTokenAsync(token);
return await UserCache.GetOrAdd(token,
async () => {
var uid = config.OverrideUid ?? res?.ClaimsIdentity.Claims.First(x => x.Type == "id").Value;
if (string.IsNullOrWhiteSpace(uid)) throw new InvalidOperationException("No user ID specified, is the access token valid?");
return await db.Users.FindAsync(uid) ?? throw new InvalidOperationException();
},
config.AuthCacheExpiry);
}
}