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

OV-8: protect routing #33

Merged
merged 30 commits into from
Aug 28, 2024
Merged

Conversation

Sanchousina
Copy link
Collaborator

@Sanchousina Sanchousina commented Aug 20, 2024

In this pr:

  • Merged OV-5: Add jwt token
  • Add authorization plugin to protect endpoints
  • Check jwt token from the header
  • Inject signed user to requests
  • Exclude sign-up and sign-in as white-routes

photo_2024-08-20_20-21-04 (3)
photo_2024-08-20_20-21-04
photo_2024-08-20_20-21-04 (2)

@Sanchousina Sanchousina added the BE Backend feature label Aug 20, 2024
@Sanchousina Sanchousina added this to the Release 1.0 milestone Aug 20, 2024
@Sanchousina Sanchousina self-assigned this Aug 20, 2024
@Sanchousina Sanchousina linked an issue Aug 20, 2024 that may be closed by this pull request
3 tasks
@Sanchousina Sanchousina changed the base branch from next to task/OV-5-JWT-token August 20, 2024 18:48
Comment on lines 27 to 30
public async findById(userId: number): Promise<UserEntity | null> {
return await this.userRepository.findById(userId);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Modify method find instead of adding this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only in user service or in user repository as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Modified only in user service for now

Copy link
Collaborator

Choose a reason for hiding this comment

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

please also modify it in the repository

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 17 to 19
const isRouteInWhiteList = options.routesWhiteList.includes(
request.url,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

also check for method in whitelist because each route can have multiple methods

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

package.json Outdated
@@ -50,6 +50,7 @@
"commit-msg": "npx commitlint --edit $1"
},
"dependencies": {
"fastify-plugin": "4.5.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

add it as backend dependency

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -1,5 +1,5 @@
type Repository<T = unknown> = {
find(): Promise<T>;
find(userId: number): Promise<T | null>;
Copy link
Collaborator

@anton-otroshchenko anton-otroshchenko Aug 21, 2024

Choose a reason for hiding this comment

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

Suggested change
find(userId: number): Promise<T | null>;
find(id: number): Promise<T | null>;

we would use this method not only in user repo if we want to find something by id

@@ -1,5 +1,5 @@
type Service<T = unknown> = {
find(): Promise<T>;
find(userId: number): Promise<T | null>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

@@ -20,6 +22,12 @@ class UserRepository implements Repository {
return user ? UserEntity.initialize(user) : null;
}

// public async findById(userId: number): Promise<UserEntity | null> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I thought I deleted that already

@stefano-lacorazza stefano-lacorazza force-pushed the task/OV-5-JWT-token branch 2 times, most recently from 080bcb2 to 1ce3a2e Compare August 25, 2024 21:41
@@ -1,5 +1,5 @@
type Repository<T = unknown> = {
find(): Promise<T>;
find(id: number): Promise<T | null>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should accept any params here, or we should rename it to findById

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed it to findById

Copy link
Collaborator

@nikita-remeslov nikita-remeslov left a comment

Choose a reason for hiding this comment

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

check comment

@nikita-remeslov nikita-remeslov merged commit f826db6 into task/OV-5-JWT-token Aug 28, 2024
1 check passed
@nikita-remeslov nikita-remeslov deleted the task/OV-8-protect-routing branch August 28, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE Backend feature
Projects
Status: To Be Tested
Development

Successfully merging this pull request may close these issues.

FEAT: Protect routing
5 participants