-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Description
As a user I should be able to know when retrieveClientToken
failed for a specific reason. See the following example:
const jsonResponse = await handleUpload({
body,
request,
onBeforeGenerateToken: async ( pathname: string, /* clientPayload?: string, */ ) => {
// Generate a client token for the browser to upload the file
// ⚠️ Authenticate users before generating the token.
// Otherwise, you're allowing anonymous uploads.
const profile = await getCurrentProfile();
if (!profile) {
console.log('User is not logged in');
throw new Error('Not authenticated');
}
if (!userAccessControl.canUser(profile).createOwn(Resources.UPLOADS).granted) {
console.log('User does not have permission to upload files');
throw new Error('You do not have permission to upload files');
}
return {
allowedContentTypes: ['application/pdf', 'text/plain'],
maximumSizeInBytes: 8_000_000,
tokenPayload: JSON.stringify({ profileId: profile.id })
};
},
onUploadCompleted: async ({ blob, tokenPayload }) => {
// ...
}
});
Assuming the above is set up in a route to handle uploads, I should receive 'You do not have permission to upload files' when the user is authenticated but not permitted to perform uploads, instead of the current 'Failed to retrieve the client token' error.
It seems the library is already set up to return the error in the body to the client, so we could attempt to parse the body for the error message.
Pascaltib, DrewVartanian and codybrouwers
Metadata
Metadata
Assignees
Labels
No labels