mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-06-04 15:12:28 +00:00
Fix bug where redirect handler would fetch wrong token
This commit is contained in:
parent
6024d44508
commit
28ff0ddc1d
2 changed files with 10 additions and 5 deletions
|
@ -13,14 +13,19 @@ public class UserRequiredRedirectMiddleware : MiddlewareDBContext
|
|||
|
||||
public override async Task InvokeAsync(HttpContext ctx, Database database)
|
||||
{
|
||||
User? user = database.UserFromWebRequest(ctx.Request);
|
||||
if (user == null || pathContains(ctx, "/logout"))
|
||||
WebToken? token = database.WebTokenFromRequest(ctx.Request);
|
||||
if (token == null || pathContains(ctx, "/logout"))
|
||||
{
|
||||
await this.next(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
WebToken token = await database.WebTokens.FirstAsync(t => t.UserId == user.UserId);
|
||||
User? user = await database.Users.FirstOrDefaultAsync(u => u.UserId == token.UserId);
|
||||
if (user == null)
|
||||
{
|
||||
await this.next(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
// Request ends with a path (e.g. /css/style.css)
|
||||
if (!string.IsNullOrEmpty(Path.GetExtension(ctx.Request.Path)) || pathContains(ctx, "/gameAssets"))
|
||||
|
|
|
@ -431,14 +431,14 @@ public class Database : DbContext
|
|||
|
||||
public User? UserFromWebRequest(HttpRequest request)
|
||||
{
|
||||
if (!request.Cookies.TryGetValue("LighthouseToken", out string? lighthouseToken) || lighthouseToken == null) return null;
|
||||
if (!request.Cookies.TryGetValue("LighthouseToken", out string? lighthouseToken)) return null;
|
||||
|
||||
return this.UserFromLighthouseToken(lighthouseToken);
|
||||
}
|
||||
|
||||
public WebToken? WebTokenFromRequest(HttpRequest request)
|
||||
{
|
||||
if (!request.Cookies.TryGetValue("LighthouseToken", out string? lighthouseToken) || lighthouseToken == null) return null;
|
||||
if (!request.Cookies.TryGetValue("LighthouseToken", out string? lighthouseToken)) return null;
|
||||
|
||||
WebToken? token = this.WebTokens.FirstOrDefault(t => t.UserToken == lighthouseToken);
|
||||
if (token == null) return null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue