Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

feature: Created a middleware for checking permissions and token validity #25

Merged
merged 3 commits into from
Mar 2, 2024
Merged

feature: Created a middleware for checking permissions and token validity #25

merged 3 commits into from
Mar 2, 2024

Conversation

multipletwigs
Copy link
Collaborator

Description of the pull request

  1. Added in a authorizationMiddleware.ts abstraction that checks for token permissions and token validity for an endpoint before reaching the endpoint.

Changes made

  1. Modified controllers to use AuthMiddleware according to the permissions they require.

Related issues

None

Testings done

  1. Running bun test passes all existing tests!

Screenshots (if any)

Checklist

  • I have written tests
  • My code does not produce new errors
  • I gave myself a code review before asking others.

The middleware makes it easy to see if bearer token exists or if the token has the required permissions before it hits the endpoint
const decodedToken = await parseToken(bearer!);
},
{
beforeHandle: AuthMiddleware(["create_thread", "*"]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this a way of saying all actions under create_thread ?

} else {
set.status = 403;
return UNAUTHORIZED_NO_PERMISSION_READ;
return UNAUTHORIZED_USER_NOT_PARTICIPANT;
Copy link
Collaborator

Choose a reason for hiding this comment

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

good catch!

@GuiBibeau GuiBibeau merged commit 53a0ac6 into AkeruAI:main Mar 2, 2024
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants