Skip to content

Comments

105 Add Authentication Check to Projects Routes#140

Open
bhuvanh66 wants to merge 3 commits intomainfrom
105-auth-projects
Open

105 Add Authentication Check to Projects Routes#140
bhuvanh66 wants to merge 3 commits intomainfrom
105-auth-projects

Conversation

@bhuvanh66
Copy link
Contributor

ℹ️ Issue

Closes #105

📝 Description

Added authentication to the projects lambda to protect its endpoints from unauthorized access. Without this, anyone with the URL could read or create projects once the lambda is made public.

Briefly list the changes made to the code:

  1. Created auth.ts to verify Cognito JWTs and load the matching user from the database
  2. Updated handler.ts to authenticate every request before running any route logic
  3. Updated both test files to mock authentication so tests call handler directly instead of the live endpoint

✔️ Verification

Clone the branch and run npx jest from apps/backend/lambdas/projects
All tests should pass without a running Cognito instance since auth is mocked

Screenshot 2026-02-19 at 6 08 48 PM Screenshot 2026-02-19 at 6 09 10 PM

@github-actions github-actions bot requested a review from Rayna-Yu February 19, 2026 23:10
github-actions bot added a commit that referenced this pull request Feb 19, 2026
Copy link
Collaborator

@nourshoreibah nourshoreibah left a comment

Choose a reason for hiding this comment

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

Just a question and a comment on permissions. Thank you and good work!

}

const authContext = await authenticateRequest(event);
if (!authContext.isAuthenticated || !authContext.user) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the right idea, but we actually want to do this in a more fine grained way.
For PUT project, user should be admin (only admin can create a project)
For the GET, the user should just be anyone authenticated

Also, looks like CI is failing because aws-jwt-verify is not installed, should just be able to npm install this

}

export interface BranchUsers {
cognito_sub: string | null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

wait omg never mind idk why i thought it was sql. ignore this comment

Copy link
Collaborator

@nourshoreibah nourshoreibah left a comment

Choose a reason for hiding this comment

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

bot

}

export interface BranchUsers {
cognito_sub: string | null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

wait omg never mind idk why i thought it was sql. ignore this comment

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.

Add Authentication Check to Projects Routes

2 participants