Add starter deck flow, admin force-logout + rename, shop flag
Auth chain: - auth.proto: add needs_starter_deck to Login/Register/ValidateToken responses - auth.proto: add RevokeAllSessions RPC - AuthGrpcHandler: populate NeedsStarterDeck from Account.StarterDeckSelectedAt - AuthGrpcHandler: track tokens in UserSessions Redis SET on create/logout - AuthGrpcHandler: implement RevokeAllSessions (Redis + Postgres) - IGatewayAuthValidator / GatewayAuthValidator: thread NeedsStarterDeck through tuples - ConnectionLoop: include needsStarterDeck in auth ack payload Client: - Auth.gd: store needs_starter_deck from auth reply; clear on logout - login_screen.gd: route to StarterDeckScreen when needs_starter_deck = true - scenes/starter_deck/: new StarterDeckScreen (fetch decks → pick → confirm → InitScreen) Admin panel: - AccountDetail.razor: Force Logout All Sessions card (Redis + Postgres revoke) - AccountDetail.razor: Change Display Name form with uniqueness check - SOR.Admin: add StackExchange.Redis package + DI registration - PrebuiltDeckEditor.razor: split into IsStarterDeck + IsAvailableInShop checkboxes - PrebuiltDeck.cs: add IsAvailableInShop field - Migration: AddPrebuiltDeckShopFlag Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -74,7 +74,12 @@ public sealed class AuthGrpcHandler : AuthService.AuthServiceBase
|
||||
|
||||
var token = await CreateSessionAsync(user.Id, context);
|
||||
_logger.LogInformation("Login succeeded for account {AccountId}", user.Id);
|
||||
return new LoginResponse { Success = true, SessionToken = token };
|
||||
return new LoginResponse
|
||||
{
|
||||
Success = true,
|
||||
SessionToken = token,
|
||||
NeedsStarterDeck = !user.StarterDeckSelectedAt.HasValue,
|
||||
};
|
||||
}
|
||||
|
||||
// ── Register ──────────────────────────────────────────────────────────────
|
||||
@@ -108,7 +113,12 @@ public sealed class AuthGrpcHandler : AuthService.AuthServiceBase
|
||||
|
||||
var token = await CreateSessionAsync(account.Id, context);
|
||||
_logger.LogInformation("Registered new account {AccountId}", account.Id);
|
||||
return new RegisterResponse { Success = true, SessionToken = token };
|
||||
return new RegisterResponse
|
||||
{
|
||||
Success = true,
|
||||
SessionToken = token,
|
||||
NeedsStarterDeck = true, // new accounts always need to select a starter deck
|
||||
};
|
||||
}
|
||||
|
||||
// ── ValidateToken ─────────────────────────────────────────────────────────
|
||||
@@ -129,9 +139,10 @@ public sealed class AuthGrpcHandler : AuthService.AuthServiceBase
|
||||
if (cached is not null)
|
||||
return new ValidateTokenResponse
|
||||
{
|
||||
Valid = true,
|
||||
UserId = cached.Id.ToString(),
|
||||
DisplayName = cached.DisplayName ?? string.Empty,
|
||||
Valid = true,
|
||||
UserId = cached.Id.ToString(),
|
||||
DisplayName = cached.DisplayName ?? string.Empty,
|
||||
NeedsStarterDeck = !cached.StarterDeckSelectedAt.HasValue,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -160,9 +171,10 @@ public sealed class AuthGrpcHandler : AuthService.AuthServiceBase
|
||||
|
||||
return new ValidateTokenResponse
|
||||
{
|
||||
Valid = true,
|
||||
UserId = account.Id.ToString(),
|
||||
DisplayName = account.DisplayName ?? string.Empty,
|
||||
Valid = true,
|
||||
UserId = account.Id.ToString(),
|
||||
DisplayName = account.DisplayName ?? string.Empty,
|
||||
NeedsStarterDeck = !account.StarterDeckSelectedAt.HasValue,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -181,6 +193,10 @@ public sealed class AuthGrpcHandler : AuthService.AuthServiceBase
|
||||
{
|
||||
session.RevokedAt = DateTimeOffset.UtcNow;
|
||||
await _db.SaveChangesAsync();
|
||||
var cache2 = _redis.GetDatabase();
|
||||
await cache2.SetRemoveAsync(
|
||||
RedisKeys.UserSessions(session.AccountId.ToString()),
|
||||
request.SessionToken);
|
||||
}
|
||||
|
||||
await _redis.GetDatabase().KeyDeleteAsync(RedisKeys.Session(request.SessionToken));
|
||||
@@ -188,6 +204,39 @@ public sealed class AuthGrpcHandler : AuthService.AuthServiceBase
|
||||
return new LogoutResponse();
|
||||
}
|
||||
|
||||
// ── RevokeAllSessions ─────────────────────────────────────────────────────
|
||||
|
||||
public override async Task<RevokeAllSessionsResponse> RevokeAllSessions(
|
||||
RevokeAllSessionsRequest request, ServerCallContext context)
|
||||
{
|
||||
if (!Guid.TryParse(request.AccountId, out var accountId))
|
||||
return new RevokeAllSessionsResponse { SessionsRevoked = 0 };
|
||||
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var cache = _redis.GetDatabase();
|
||||
var userKey = RedisKeys.UserSessions(accountId.ToString());
|
||||
|
||||
// Grab all raw tokens from the Redis SET, then delete each session key.
|
||||
var members = await cache.SetMembersAsync(userKey);
|
||||
foreach (var member in members)
|
||||
await cache.KeyDeleteAsync(RedisKeys.Session(member!));
|
||||
await cache.KeyDeleteAsync(userKey);
|
||||
|
||||
// Revoke all active Postgres sessions for this account.
|
||||
var sessions = await _db.AccountSessions
|
||||
.Where(s => s.AccountId == accountId && s.RevokedAt == null && s.ExpiresAt > now)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var s in sessions)
|
||||
s.RevokedAt = now;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
_logger.LogInformation("Revoked {Count} sessions for account {AccountId}",
|
||||
sessions.Count, accountId);
|
||||
return new RevokeAllSessionsResponse { SessionsRevoked = sessions.Count };
|
||||
}
|
||||
|
||||
// ── Account Properties ────────────────────────────────────────────────────
|
||||
|
||||
public override async Task<GetAccountPropertyResponse> GetAccountProperty(
|
||||
@@ -322,10 +371,10 @@ public sealed class AuthGrpcHandler : AuthService.AuthServiceBase
|
||||
});
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
await _redis.GetDatabase().StringSetAsync(
|
||||
RedisKeys.Session(token),
|
||||
accountId.ToString(),
|
||||
expiry - DateTimeOffset.UtcNow);
|
||||
var ttl = expiry - DateTimeOffset.UtcNow;
|
||||
var cache = _redis.GetDatabase();
|
||||
await cache.StringSetAsync(RedisKeys.Session(token), accountId.ToString(), ttl);
|
||||
await cache.SetAddAsync(RedisKeys.UserSessions(accountId.ToString()), token);
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user