Skip to content

Setting up auth#217

Open
SamNie2027 wants to merge 14 commits intomainfrom
188-setting-up-auth-3
Open

Setting up auth#217
SamNie2027 wants to merge 14 commits intomainfrom
188-setting-up-auth-3

Conversation

@SamNie2027
Copy link
Copy Markdown
Collaborator

ℹ️ Issue

Closes #188

📝 Description

Added Authentication - created two users in AWS console:

After login, the backend database is queried to get the user which informs the frontend about the userType.

Protected the /Admin routes with the Admin userType

Protected the /Candidate routes with the Candidate userType.

The login for the admin will go to the admin landing page which is the page that shows all of the candidates.
The login for the candidate will go to the candidate view my application page which ... shows nothing because it isn't implemented yet.

Logout by going to /logout and pressing the button

Make sure to drop and recreate the database and reseed it.

✔️ Verification

I went through both user flows with login and verified the users in aws cognito.

Copy link
Copy Markdown

Copilot AI left a comment

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 end-to-end Cognito/Amplify authentication flow that lets the frontend authenticate with Cognito, resolve an app-specific UserType from the backend database, and protect admin/candidate routes accordingly (Issue #188).

Changes:

  • Frontend: configure Amplify Auth, add login/signup/logout screens, cache UserType in session storage, and add route guards (RequireAuth / RequireRole) with role-based landing redirects.
  • Frontend: attach Cognito ID token to API requests and add a getUserByEmail API call to resolve the current user role.
  • Backend: configure Cognito JWT strategy from env vars, enrich request.user from DB via email claim, and adjust seeds to match new test Cognito users.

Reviewed changes

Copilot reviewed 23 out of 26 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
package.json Adds aws-amplify dependency for frontend auth.
example.env Documents new Vite Cognito env vars.
apps/frontend/src/vite-env.d.ts Types Vite env vars for Cognito + API base URL.
apps/frontend/src/main.tsx Calls configureAmplify() at app startup.
apps/frontend/src/containers/login.tsx New login form + session userType resolution.
apps/frontend/src/containers/signup.tsx New signup form using Amplify Auth.
apps/frontend/src/containers/logout.tsx New logout screen calling Amplify sign-out.
apps/frontend/src/components/NavBar/NavBar.tsx Updates admin dashboard link to real route.
apps/frontend/src/auth/session.ts Adds sessionStorage helpers for caching UserType.
apps/frontend/src/auth/current-session-user-type.ts Fetches Cognito email + backend userType and caches it.
apps/frontend/src/auth/cognito.ts Wraps Amplify Auth primitives (sign-in/up/out, token retrieval).
apps/frontend/src/auth/amplify.ts Centralizes Amplify configuration + env assertions.
apps/frontend/src/auth/RoleHomeRedirect.tsx Redirects / to role-specific landing page.
apps/frontend/src/auth/RequireRole.tsx Route guard enforcing allowed UserTypes.
apps/frontend/src/auth/RequireAuth.tsx Route guard enforcing Cognito authentication.
apps/frontend/src/app.tsx Adds auth routes + protected admin/candidate route trees.
apps/frontend/src/api/types.ts Adds User type used by /users/email/:email response.
apps/frontend/src/api/apiClient.ts Adds auth header interceptor + getUserByEmail().
apps/backend/src/users/users.controller.ts Adds logging and reads auth header on user lookup.
apps/backend/src/seeds/seed.ts Updates seeded emails + aligns learner/volunteer info with app types.
apps/backend/src/interceptors/current-user.interceptor.ts Enriches request user from DB via JWT email claim.
apps/backend/src/auth/jwt.strategy.ts Validates Cognito JWTs using issuer/audience from env config.
apps/backend/src/auth/aws-exports.ts Reads Cognito config from env vars instead of hardcoding.
apps/backend/src/auth/auth.service.ts Makes AWS credentials optional + clarifies docstrings.

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 23 out of 25 changed files in this pull request and generated 7 comments.


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

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.

Start to setup Auth using cognito and amplify

2 participants