-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
||
|
@@ -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 ={} | ||
try{ | ||
payload = await this.jwtWrapperService.verifyWorkspaceToken( | ||
query['token'], | ||
'FILE', | ||
); | ||
|
||
) | ||
}catch (error) { | ||
if(error instanceof AuthException && error.code === AuthExceptionCode.UNAUTHENTICATED ){ | ||
return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: Missing semicolons at line endings |
||
} | ||
else{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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...) { throw ... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
}); | ||
|
There was a problem hiding this comment.
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 = {}'
There was a problem hiding this comment.
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