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

User workspace middleware throws 401 if token is invalid #5245

Merged
merged 2 commits into from
May 2, 2024

Conversation

Weiko
Copy link
Member

@Weiko Weiko commented May 2, 2024

Context

Currently, this middleware validates the token and stores the user, workspace and cacheversion in the request object.
It only does so when a token is provided and ignores the middleware logic if not. If the token is invalid or expired, the exception is swallowed.

This PR removes the try/catch and adds an allowlist to skip the token validation for operations executed while not signed-in.
I don't know a better way to do that with Nestjs. We can't easily add the middleware per resolver without refactoring the flexible schema engine so I'm doing it the other way around.

Fixes #5224

@Weiko Weiko requested a review from charlesBochet May 2, 2024 10:09
@Weiko Weiko merged commit 9a116b0 into main May 2, 2024
5 checks passed
@Weiko Weiko deleted the c--throw-401-user-workspace-middleware branch May 2, 2024 10:54
i-am-chitti pushed a commit to i-am-chitti/twenty that referenced this pull request May 4, 2024
## Context
Currently, this middleware validates the token and stores the user,
workspace and cacheversion in the request object.
It only does so when a token is provided and ignores the middleware
logic if not. If the token is invalid or expired, the exception is
swallowed.

This PR removes the try/catch and adds an allowlist to skip the token
validation for operations executed while not signed-in.
I don't know a better way to do that with Nestjs. We can't easily add
the middleware per resolver without refactoring the flexible schema
engine so I'm doing it the other way around.

Fixes twentyhq#5224
arnavsaxena17 pushed a commit to arnavsaxena17/twenty that referenced this pull request Oct 6, 2024
## Context
Currently, this middleware validates the token and stores the user,
workspace and cacheversion in the request object.
It only does so when a token is provided and ignores the middleware
logic if not. If the token is invalid or expired, the exception is
swallowed.

This PR removes the try/catch and adds an allowlist to skip the token
validation for operations executed while not signed-in.
I don't know a better way to do that with Nestjs. We can't easily add
the middleware per resolver without refactoring the flexible schema
engine so I'm doing it the other way around.

Fixes twentyhq#5224
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server should throw relevant errors when token is expired, so apps can refresh their tokens accordingly
2 participants