File tree Expand file tree Collapse file tree
apps/cursor/src/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,11 +31,15 @@ export function AddCompanyButton({ redirect }: { redirect?: boolean }) {
3131 // Adding a company requires an authenticated session: the save action is
3232 // auth-guarded and the logo upload hits an auth-only storage policy. Send
3333 // signed-out visitors to sign in instead of into a form that can't succeed.
34- if ( ! isAuthenticated ) {
34+ if ( isAuthenticated === false ) {
3535 router . push ( `/login?next=${ pathname } ` ) ;
3636 return ;
3737 }
3838
39+ if ( isAuthenticated === null ) {
40+ return ;
41+ }
42+
3943 setAddCompany ( { addCompany : true , redirect } ) ;
4044 } ;
4145
Original file line number Diff line number Diff line change @@ -40,8 +40,10 @@ export default function UploadLogo({
4040 // Show an optimistic preview while the upload is in flight. It is reverted
4141 // below if the upload fails so the UI never shows an image that wasn't
4242 // actually saved.
43+ let allowReaderPreview = true ;
4344 const reader = new FileReader ( ) ;
4445 reader . onload = ( e ) => {
46+ if ( ! allowReaderPreview ) return ;
4547 setPreview ( e . target ?. result as string ) ;
4648 } ;
4749 reader . readAsDataURL ( file ) ;
@@ -59,6 +61,7 @@ export default function UploadLogo({
5961
6062 if ( ! user ) {
6163 toast . error ( "Please sign in to upload an image." ) ;
64+ allowReaderPreview = false ;
6265 setPreview ( previousPreview ) ;
6366 return ;
6467 }
@@ -82,13 +85,15 @@ export default function UploadLogo({
8285 data : { publicUrl } ,
8386 } = supabase . storage . from ( "avatars" ) . getPublicUrl ( path ) ;
8487
88+ allowReaderPreview = false ;
8589 setPreview ( publicUrl ) ;
8690 onUpload ?.( publicUrl ) ;
8791 } catch ( error ) {
8892 console . error ( "Error uploading file:" , error ) ;
8993 toast . error (
9094 error instanceof Error ? error . message : "Failed to upload image." ,
9195 ) ;
96+ allowReaderPreview = false ;
9297 setPreview ( previousPreview ) ;
9398 } finally {
9499 setIsUploading ( false ) ;
You can’t perform that action at this time.
0 commit comments