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

Fix : #8825 If attachment token expires, it throws a 500 error instead of Unauthenticated #9043

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
HttpStatus,
Injectable,
} from '@nestjs/common';
import { AuthException, AuthExceptionCode } from 'src/engine/core-modules/auth/auth.exception';

import { JwtWrapperService } from 'src/engine/core-modules/jwt/services/jwt-wrapper.service';

Expand All @@ -15,20 +16,31 @@ export class FilePathGuard implements CanActivate {
async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest();
const query = request.query;

if (!query || !query['token']) {
return false;
}

const payload = await this.jwtWrapperService.verifyWorkspaceToken(
let payload:any ={}
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Missing space after colon in type declaration. Should be 'payload: any = {}'

Copy link
Member

Choose a reason for hiding this comment

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

Please check run your linter: npx nx run twenty-server:lint

try{
payload = await this.jwtWrapperService.verifyWorkspaceToken(
query['token'],
'FILE',
);

)
}catch (error) {
if(error instanceof AuthException && error.code === AuthExceptionCode.UNAUTHENTICATED ){
return false
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Missing semicolons at line endings

}
else{
Copy link
Member

Choose a reason for hiding this comment

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

no need for else as you are already returning

if (error instance of...) {
return
}

throw ...

Copy link
Member

Choose a reason for hiding this comment

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

actually forget about this comment as I think we should have another strategy :)

throw new AuthException(
'TOKEN VERIFICATION FAILED',
AuthExceptionCode.INTERNAL_SERVER_ERROR,
);
}
}
if (!payload.workspaceId) {
return false;
}

const decodedPayload = await this.jwtWrapperService.decode(query['token'], {
json: true,
});
Expand Down
Loading