RequireLocalStorageToken
@quik/storage-express / RequireLocalStorageToken
Function: RequireLocalStorageToken()
RequireLocalStorageToken(
purpose): <This,Args,Return>(target,context) =>MethodDecoratorType<This,Args,Return>
Defined in: storage-express/src/decorators/RequireLocalStorageToken.ts:33
Endpoint middleware decorator that verifies a signed local storage token before the handler runs.
Expects the endpoint's query parameters to include a token field carrying a token produced by
LocalSignature.sign/QLocalStorageEngine.getSignedUploadURL/getSignedDownloadURL. Throws
StorageInvalidSignedURLError, StorageSignedURLExpiredError, or
StorageSignedURLPurposeMismatchError when the token is missing, malformed, expired, or was
issued for a different purpose; otherwise execution continues and the verified storage path is made
available to the handler via event.getObject(LOCAL_STORAGE_TOKEN_PATH_KEY).
Parameters
purpose
QLocalSignaturePurpose
Purpose the token must have been issued for.
Returns
<This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>
Throws
StorageInvalidSignedURLError When the token query parameter is missing or malformed.
Throws
StorageSignedURLPurposeMismatchError When the token was issued for a different purpose.
Example
@Decorators.Endpoint.GET("/download", { query: LocalStorageTokenQuery })
@RequireLocalStorageToken("download")
public async download(event: QQueryParametersOnlyEvent<LocalStorageTokenQuery>): Promise<IQResponse> {
const path = event.getObject<string>(LOCAL_STORAGE_TOKEN_PATH_KEY);
// ...
}