Skip to content

Commit

Permalink
Add logging to auth to debug login issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Zikoat committed Jul 24, 2024
1 parent c7bbc15 commit e44313b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,50 @@ public TeamTypeFilter(TeamType[] types, ILeagueService leagueService)

public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
Console.WriteLine("Entering OnAuthorizationAsync method.");

if (_authorizedTeamTypes.Length > 0)
{
string? code = default;
if (context.HttpContext.Request.Headers.TryGetValue("x-ubg-teamcode", out var codeFromHeader))
{
code = codeFromHeader;
Console.WriteLine($"Team code found in headers: {code}");
}
else if (context.RouteData.Values.TryGetValue("code", out var codeFromRoute))
{
code = codeFromRoute?.ToString();
Console.WriteLine($"Team code found in route data: {code}");
}

if (string.IsNullOrEmpty(code))
{
Console.WriteLine("Team code is missing.");
context.Result = new ExceptionResult(Strings.MissingTeamCode, 401);
}
else
{
var team = await _leagueService.GetTeamByCode(code!);
if (team is null)
{
Console.WriteLine($"Unknown team code: {code}");
context.Result = new ExceptionResult(Strings.UnknownTeamCode, 401);
}
else if (!_authorizedTeamTypes.Contains(team.Type))
{
Console.WriteLine($"Team unauthorized. Team type: {team.Type}");
context.Result = new ExceptionResult(Strings.TeamUnathorized, 403);
}

context.HttpContext.Items["ValidatedTeam"] = team;
else
{
Console.WriteLine($"Team authorized: {team.TeamId}");
context.HttpContext.Items["ValidatedTeam"] = team;
}
}
}
Console.WriteLine("Exiting OnAuthorizationAsync method.");
}

}

}
12 changes: 11 additions & 1 deletion backend/Buk.UniversalGames.Api/Controllers/GamesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ public async Task<ActionResult<List<TeamStatus>>> GetGameRanking(int gameId, int
[HttpGet("/matches")]
public async Task<ActionResult<List<MatchListItem>>> GetMatches()
{
Console.WriteLine("Entering GetMatches method.");

if (HttpContext.Items["ValidatedTeam"] is not Team team)
{
Console.WriteLine("Team not found in HttpContext.Items.");
return BadRequest("Team not found");
}
return await _gameService.GetMatches(team);

Console.WriteLine($"Team found: {team.Code} {team.Name} {team.TeamId}");

var matches = await _gameService.GetMatches(team);

Console.WriteLine("Matches retrieved successfully.");

return matches;
}
}

0 comments on commit e44313b

Please sign in to comment.