Skip to content

107 add authentication check to users route#129

Merged
mehanana merged 14 commits intomainfrom
107-Add-Authentication-Check-to-Users-Route
Apr 12, 2026
Merged

107 add authentication check to users route#129
mehanana merged 14 commits intomainfrom
107-Add-Authentication-Check-to-Users-Route

Conversation

@mehanana
Copy link
Copy Markdown
Contributor

@mehanana mehanana commented Feb 11, 2026

ℹ️ Issue

Closes #107

📝 Description

Write a short summary of what you added. Why is it important? Any member of C4C should be able to read this and understand your contribution -- not just your team members.

Added authentication to the users lambda route to protect it from anyone accessing the endpoints.

Briefly list the changes made to the code:

  1. Created an auth.ts file to retrieve tokens and verify through cognito, and then determine if the user is an admin or not
  2. Updated each endpoint in handler.ts to check authorization of the user before running the business logic
  3. Updated both test files to mock authorization to ensure the endpoints will work.

✔️ Verification

What steps did you take to verify your changes work? These should be clear enough for someone to be able to clone the branch and follow the steps themselves.

Provide screenshots of any new components, styling changes, or pages.

Tests ran after authorization was added:
Screenshot 2026-02-11 170500
Screenshot 2026-02-11 170651

🏕️ (Optional) Future Work / Notes

Did you notice anything ugly during the course of this ticket? Any bugs, design challenges, or unexpected behavior? Write it down so we can clean it up in a future ticket!

@github-actions github-actions Bot requested a review from bhuvanh66 February 11, 2026 22:08
github-actions Bot added a commit that referenced this pull request Feb 11, 2026
Copy link
Copy Markdown
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.

Awesome work with the auth logic!! Just a couple of tweaks here

"sourceMap": true
},
"include": ["*.ts"],
"include": ["*.ts", "test/test-cognito.ts"],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need this? I think *.ts catches it

Comment thread example.env Outdated
NX_DB_PORT=5432,

COGNITO_USER_POOL_ID=us-east-2_CxTueqe6g
COGNITO_CLIENT_ID=570i6ocj0882qu0ditm4vrr60f
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ideally we shouldn't be pushing these for security. You can put them in .env on your local and git will ignore them

Comment thread package.json
"@nestjs/typeorm": "^10.0.0",
"@types/pg": "^8.15.5",
"amazon-cognito-identity-js": "^6.3.5",
"aws-jwt-verify": "^5.1.1",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

GHA failure seems to have something to do with this package, i'd check on it/compare to PRs that are passing these checks

Comment thread yarn.lock Outdated

"@types/aws-lambda@^8.10.160":
version "8.10.160"
resolved "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.160.tgz"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah it looks like you have 2 package managers. we us npm instead of yarn! might be causing the CI failure

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

to be clear, we don't need this lock file

clientId: COGNITO_CLIENT_ID,
});
}
return verifier;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Either you'll need env vars to run this, or jus tmmock cognito

Comment thread example.env Outdated
Comment thread apps/backend/lambdas/users/handler.ts Outdated

// GET /{userId}
if (normalizedPath.startsWith('/') && normalizedPath.split('/').length === 2 && method === 'GET') {
const authCheck = checkAuthorization(authContext, 'ADMIN_OR_SELF');
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.

could abstract this repeated code out with helper function

github-actions Bot added a commit that referenced this pull request Feb 22, 2026
Copy link
Copy Markdown
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.

LGTM!

@nourshoreibah
Copy link
Copy Markdown
Collaborator

Looks like it is still missing that module and it's failing ci, but code looks good

@mehanana mehanana requested a review from bhuvanh66 April 12, 2026 16:42
@Vaibhav978 Vaibhav978 self-requested a review as a code owner April 12, 2026 17:28
Copy link
Copy Markdown
Contributor

@Vaibhav978 Vaibhav978 left a comment

Choose a reason for hiding this comment

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

lgtm

@mehanana mehanana enabled auto-merge April 12, 2026 18:19
@mehanana mehanana added this pull request to the merge queue Apr 12, 2026
Merged via the queue into main with commit ece8019 Apr 12, 2026
13 checks passed
@mehanana mehanana deleted the 107-Add-Authentication-Check-to-Users-Route branch April 12, 2026 19:00
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 Users Routes

4 participants