Avatar Upload Issue: Session Cookie Size and Upload Timing
We're facing a challenge with our avatar upload implementation:
Problem: When a user uploads an avatar during signup, the base64-encoded image is stored in the session cookie, making it too large and causing the app to crash
Potential solution: We need to disable cache for the Session cookie
The key dilemma is determining when to upload the image to Storage during the signup lifecycle:
Too early: If we upload before user creation is complete and the signup fails, we'll have orphaned images in storage
Too late: If we upload after user creation (e.g., in a DB hook), the session cookie is already created with the base64 image data, which crashes the app
We seem to be stuck between two bad options:
Use a uncached session cookie with base64 image
Use cached session but no image uploads on registration;
Also can use cached session and save image in after hook, but make sure to have: requireEmailVerification: true, and sendOnSignUp: true, so session is not created befor user verifies their email -> this woeks fine, but as soon as you disable one of this options - your app goes 'BOOOM' on user creation with image uploaded
Has anyone solved a similar problem with avatar uploads during signup? Specifically looking for insights on "Hooks and DB Hooks in the sign-up/email lifecycle" that would help address this timing issue.
Solution:Jump to solution
you can use before hook or upload the image prior to calling signUp and then pass the image link instead of base64 to better auth.
2 Replies
Solution
you can use before hook or upload the image prior to calling signUp and then pass the image link instead of base64 to better auth.
Yes, and if sign up fails - we'll have orphaned images in storage.