Skip to content

Feat/auth#133

Open
Blaze34536 wants to merge 17 commits into
mainfrom
feat/auth
Open

Feat/auth#133
Blaze34536 wants to merge 17 commits into
mainfrom
feat/auth

Conversation

@Blaze34536

Copy link
Copy Markdown
Contributor

implemented auth

Copilot AI review requested due to automatic review settings March 19, 2026 02:51
@Blaze34536 Blaze34536 self-assigned this Mar 19, 2026
@Blaze34536 Blaze34536 linked an issue Mar 19, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an authentication flow centered on Supabase + Google OAuth, wiring up new backend auth endpoints and updating the frontend login link to initiate the flow.

Changes:

  • Updated the Svelte login page to route sign-in through /api/auth/google.
  • Introduced backend AuthController, IAuthService, and AuthService for OAuth callback handling and token→user lookup.
  • Added JWT bearer authentication/authorization middleware registration and updated CORS policy naming.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
frontend/src/routes/login/+page.svelte Points the login CTA to the new Google auth endpoint.
backend/TRFSAE.MemberPortal.API/Controllers/AuthController.cs Implements Google OAuth redirect, callback exchange, /me, logout, and a temporary test endpoint.
backend/TRFSAE.MemberPortal.API/Interfaces/IAuthService.cs Defines auth service contract used by the controller.
backend/TRFSAE.MemberPortal.API/Services/AuthService.cs Implements token validation and user lookup from a Supabase JWT.
backend/TRFSAE.MemberPortal.API/Program.cs Registers auth service, configures JWT bearer auth, enables UseAuthentication(), and renames CORS policy.
backend/TRFSAE.MemberPortal.API/Enums.cs Adds Role.Unverified enum value.
Comments suppressed due to low confidence (1)

backend/TRFSAE.MemberPortal.API/Program.cs:82

  • CORS policy allows only http://localhost:3000, but the dev frontend is configured to run on http://127.0.0.1:3000 (see frontend/vite.config.ts). If the frontend ever calls the API directly (without the dev proxy) this will fail CORS with credentials. Consider allowing both hosts in dev and/or moving allowed origins to configuration.
    options.AddPolicy("AllowSvelteApp", policy =>
    {
        policy.WithOrigins("http://localhost:3000")
              .AllowAnyHeader()
              .AllowAnyMethod()
              .AllowCredentials();
    });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +44 to +50
var handler = new JwtSecurityTokenHandler();
var jwtToken = handler.ReadJwtToken(token);
var userIdClaim = jwtToken.Claims.FirstOrDefault(c => c.Type == "sub")?.Value;
if (userIdClaim == null) return null;

var userDto = await _userService.GetUserAsync(Guid.Parse(userIdClaim));
if (userDto == null) return null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hes right but probablyj ust implement it differently

Comment on lines +69 to +70
// Sync functionality removed to avoid changes outside auth
await Task.CompletedTask;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is now out of my paygrade; what do you think

Comment on lines +43 to +58
var supabaseUrl = builder.Configuration["SupabaseUrl"];
var jwtSecret = builder.Configuration["SupabaseJwtSecret"];

var url = builder.Configuration["SupabaseUrl"] ?? throw new InvalidOperationException("Supabase URL is not configured.");
var key = builder.Configuration["SupabaseKey"] ?? throw new InvalidOperationException("Supabase Key is not configured.");
return new Client(url, key, options);
});
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = $"{supabaseUrl}/auth/v1",

ValidateAudience = false,

ValidateLifetime = true,

ValidateIssuerSigningKey = true,
IssuerSigningKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(
System.Text.Encoding.UTF8.GetBytes(jwtSecret!)
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bah

Comment thread backend/TRFSAE.MemberPortal.API/Controllers/AuthController.cs Outdated
Comment thread backend/TRFSAE.MemberPortal.API/Controllers/AuthController.cs
Comment on lines +83 to +86
catch (Exception ex)
{
return StatusCode(500, "Authentication failed: " + ex.Message);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The copilot suggestion is right; but we don't really have to worry about it for now, we should probably just revisit this later before we release/not even bother bc this is member portal

Comment thread backend/TRFSAE.MemberPortal.API/Controllers/AuthController.cs Outdated
Comment on lines +22 to +31
public bool ValidateSupabaseToken(string token)
{
if (string.IsNullOrEmpty(token)) return false;

try
{
var handler = new JwtSecurityTokenHandler();
var jwtToken = handler.ReadJwtToken(token);
return jwtToken.ValidTo > DateTime.UtcNow;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what copilot said (man ts is gonna take my job)

Comment thread backend/TRFSAE.MemberPortal.API/Enums.cs
Blaze34536 and others added 2 commits March 18, 2026 21:57
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@liangricky7 liangricky7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copilot stole my job

Comment on lines +83 to +86
catch (Exception ex)
{
return StatusCode(500, "Authentication failed: " + ex.Message);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The copilot suggestion is right; but we don't really have to worry about it for now, we should probably just revisit this later before we release/not even bother bc this is member portal

Comment on lines +22 to +31
public bool ValidateSupabaseToken(string token)
{
if (string.IsNullOrEmpty(token)) return false;

try
{
var handler = new JwtSecurityTokenHandler();
var jwtToken = handler.ReadJwtToken(token);
return jwtToken.ValidTo > DateTime.UtcNow;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what copilot said (man ts is gonna take my job)

Comment on lines +44 to +50
var handler = new JwtSecurityTokenHandler();
var jwtToken = handler.ReadJwtToken(token);
var userIdClaim = jwtToken.Claims.FirstOrDefault(c => c.Type == "sub")?.Value;
if (userIdClaim == null) return null;

var userDto = await _userService.GetUserAsync(Guid.Parse(userIdClaim));
if (userDto == null) return null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hes right but probablyj ust implement it differently

Comment on lines +69 to +70
// Sync functionality removed to avoid changes outside auth
await Task.CompletedTask;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is now out of my paygrade; what do you think

Comment on lines +43 to +58
var supabaseUrl = builder.Configuration["SupabaseUrl"];
var jwtSecret = builder.Configuration["SupabaseJwtSecret"];

var url = builder.Configuration["SupabaseUrl"] ?? throw new InvalidOperationException("Supabase URL is not configured.");
var key = builder.Configuration["SupabaseKey"] ?? throw new InvalidOperationException("Supabase Key is not configured.");
return new Client(url, key, options);
});
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = $"{supabaseUrl}/auth/v1",

ValidateAudience = false,

ValidateLifetime = true,

ValidateIssuerSigningKey = true,
IssuerSigningKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(
System.Text.Encoding.UTF8.GetBytes(jwtSecret!)
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend - Auth System

3 participants