Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication #30

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Authentication #30

wants to merge 11 commits into from

Conversation

balintking
Copy link
Contributor

Implemented AuthSch authentication, tho I'm concerned about the synchronization part with Pék. Should we update the membership information on every sign-in, or should we implement something like an approval system on incoming changes? So, I'm open to any constructive observations.

This pull request introduces several significant updates to the backend application, including the addition of authentication with AuthSch, database schema changes, and various improvements to the codebase. Below are the most important changes grouped by theme.

Authentication and Authorization:

  • Added AuthSch authentication strategy, including login and callback endpoints, and JWT strategy for token validation (apps/backend/src/auth/auth.controller.ts, apps/backend/src/auth/auth.module.ts, apps/backend/src/auth/auth.service.ts, apps/backend/src/auth/authsch.strategy.ts, apps/backend/src/auth/jwt.strategy.ts). [1] [2] [3] [4] [5]

Database Schema Changes:

  • Added new columns and enums to support club memberships, dorm residency, and user roles, and removed deprecated columns (apps/backend/prisma/migrations/20241223144157_authsch/migration.sql, apps/backend/prisma/migrations/20241223185015_user_update/migration.sql, apps/backend/prisma/migrations/20241224023154_clubmembership/migration.sql, apps/backend/prisma/migrations/20241224031453_membership_updated_at/migration.sql, apps/backend/prisma/schema.prisma). [1] [2] [3] [4] [5] [6] [7]

Configuration Updates:

  • Updated .env.example to include new environment variables for authentication and application URLs (apps/backend/.env.example).

Dependency Updates:

  • Added new dependencies for authentication and JWT handling (apps/backend/package.json).

API and Code Enhancements:

  • Introduced DTOs and entity classes for handling club memberships and updated existing services to use new user attributes (apps/backend/src/memberships/dto/create-membership.dto.ts, apps/backend/src/memberships/dto/update-membership.dto.ts, apps/backend/src/memberships/entities/membership.entity.ts, apps/backend/src/band/band.service.ts). [1] [2] [3] [4]
  • Enabled CORS and added OpenAPI (Swagger) documentation setup (apps/backend/src/main.ts).

Integrated Swagger for API documentation using OpenAPI in the backend.
Introduced a new `authSchId` column in the `User` table to store unique identifiers for authentication with AuthSch.
Dropped the CardRight table. Updated the User and ProfilePicture models. Adjusted DTOs and entities to reflect these schema changes.
Dropped the CardRight table. Updated the User and ProfilePicture models. Adjusted DTOs and entities to reflect these schema changes.
Introduced a new authentication module utilizing AuthSCH for login and JWT for session handling. This includes controllers, services, and strategy definitions for handling authentication, along with necessary dependency updates and environment variables.
Configured CORS to allow requests from the frontend URL specified in the environment variables. Supported HTTP methods include GET, PUT, PATCH, POST, and DELETE, with credentials enabled for secure cross-origin communication.
Updated database schema to introduce `DormResidency` and `ClubMembership` models and enums, replacing previous user-level fields like `isDormResident` and `roomAccess` and adjusted related code.
Introduced a new optional field, `clubMembershipStatusUpdatedAt`, to the User model in Prisma schema and database migrations. This allows tracking when a user's club membership status was last updated.
Introduced a new Memberships module, including DTOs, service, and controller, establishing foundational CRUD functionality for managing memberships.
Implemented logic to update or remove club membership information based on user profiles from AuthSch. Extended `.env.example` with new environment variables to support membership status checks.
@balintking balintking added question Further information is requested backend Backend feature labels Dec 24, 2024
@balintking balintking self-assigned this Dec 24, 2024
Copy link

vercel bot commented Dec 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mmmk-web-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 24, 2024 5:37pm

@balintking
Copy link
Contributor Author

@Tschonti What can we do about the incompatibility issue?
error @kir-dev/[email protected]: The engine "node" is incompatible with this module. Expected version "^20.0.0". Got "22.12.0"

@Tschonti
Copy link
Member

Oof sorry, I'll update the package soon

@Tschonti
Copy link
Member

update the package to v2.2.2 and it should be okay

@balintking balintking linked an issue Dec 24, 2024 that may be closed by this pull request
Copy link
Collaborator

@justnyx justnyx left a comment

Choose a reason for hiding this comment

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

I have reviewed the changes and it looked good, as far, as I could tell. I have left a comment for the auth service.

Regarding the PÉK sync, I don't think it's necessary to update the info on every sign in, since it doesn't change that often. Could you explain what you mean by approval system? Isn't there a PÉK API, that we could use to monitor changes made to MMMK and sync the users accordingly?

});
}

async syncClubMembership(user: User, userProfile: AuthSchProfile): Promise<User> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't there be a problem with this if PÉK contains depricated information? For example, I'm currently a gatekeeper in MMMK, but on PÉK I don't have the gatekeeper role.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend feature question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Authentication
3 participants