Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Cannot read properties of null (reading 'photoURL') #1443

Closed
mrleblanc101 opened this issue Oct 11, 2023 · 4 comments
Closed

Cannot read properties of null (reading 'photoURL') #1443

mrleblanc101 opened this issue Oct 11, 2023 · 4 comments

Comments

@mrleblanc101
Copy link

mrleblanc101 commented Oct 11, 2023

Reproduction

https://github.com/mrleblanc101/neobigben

Steps to reproduce the bug

  • Login
  • Click the User acount menu in the top-right
  • Logout
  • This warning message appear in the console:

Cannot read properties of null (reading 'photoURL')

But my logout method redirect to an empty logout page with an empty layout before login out, so the user account component is not even mounted anymore when this error happen.
Here is my logout method:

async function logout() {
    const auth = useFirebaseAuth()!;
    const localeRoute = useLocaleRoute();
    const store = useIndexStore();

    await navigateTo( // navigate to an empty page with an empty layout
        localeRoute({
            name: 'logout',
        }),
    );
    store.$reset(); // reset my useCollection
    await signOut(auth); // signout
    return navigateTo( // redirect to guarded login page after logout
        localeRoute({
            name: 'login',
        }),
    );
}

Expected behavior

There should not cause a warning in an unmounted component

Actual behavior

This cause an warning on a unmounted component

Additional information

No response

@mrleblanc101
Copy link
Author

Using optional chaining user?.photoURL or v-if fix the issue but I do not understand why

@mrleblanc101
Copy link
Author

Maybe it's related, but after using the above workaround, I get this error on logout:

Uncaught (in promise) FirebaseError: Function where() called with invalid data. Unsupported field value: undefined.

My useCollection has a where where('user', '==', user.value?.uid), to only get data from the logged in user as bellow:

const entries = useCollection<Entry>(
    computed(() =>
        query(
            collection(db, 'entries').withConverter(dateConverter),
            where('user', '==', user.value?.uid),
            where('date', '>=', weekStart.value),
            where('date', '<=', weekEnd.value),
        ),
    ),
    {
        ssrKey: 'entries',
    },
);

So before my logout, I call store.$reset which should "unbind" the useCollection ?
I'm not sure if it's the right way, but pinia does not have a build-in store.reset for setup store and vue-fire has un $unbind but only in the option API, so maybe i'm doing something wrong.

function $reset() {
    projects.value = [];
    priorities.value = [];
    entries.value = [];
}

@mrleblanc101
Copy link
Author

mrleblanc101 commented Oct 11, 2023

I also get this, so I guess I'm doing something wrong when I try to force Vue to stop triggering my useCollection when I logout.

[Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core

@mrleblanc101
Copy link
Author

I wonder if this is not a bug with Nuxt 3, as clearly my "on loged out" should be called after the mount of the logout page.
I even added a nextTick just to be sure !
Screenshot 2023-10-11 at 12 37 03 AM

async function logout() {
    console.log('on logout');
    const auth = useFirebaseAuth()!;
    const localeRoute = useLocaleRoute();
    const store = useIndexStore();

    await navigateTo(
        localeRoute({
            name: 'logout',
        }),
    );
    store.$reset();
    await nextTick();
    console.log('loged out');
    await signOut(auth);
    return navigateTo(
        localeRoute({
            name: 'login',
        }),
    );
}

@vuejs vuejs locked and limited conversation to collaborators Oct 11, 2023
@posva posva converted this issue into discussion #1444 Oct 11, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant