Skip to content

Commit

Permalink
update TokenRefreshMiddleware.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
junioranheu authored Jan 10, 2025
1 parent 7df5f5e commit 080fff8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Auth.API/Middlewares/TokenRefreshMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ public async Task InvokeAsync(HttpContext context)
using IServiceScope scope = _scopeFactory.CreateScope();
ICreateRefreshToken createRefreshToken = scope.ServiceProvider.GetRequiredService<ICreateRefreshToken>();

string newJwtToken = await createRefreshToken.RefreshToken(userId);

// Atualizar contextos;
context.Response.Headers.Authorization = $"Bearer {newJwtToken}";
context.Request.Headers.Authorization = $"Bearer {newJwtToken}";
try
{
string newJwtToken = await createRefreshToken.RefreshToken(userId);

// Atualizar contextos;
context.Response.Headers.Authorization = $"Bearer {newJwtToken}";
context.Request.Headers.Authorization = $"Bearer {newJwtToken}";
}
catch (Exception)
{
context.Response.Headers.Authorization = string.Empty;
context.Request.Headers.Authorization = string.Empty;
}
}
}

await _next(context);
}
}
}

0 comments on commit 080fff8

Please sign in to comment.