Skip to content

Fetch server data on page load (Firebase example) #193

Answered by sqllyw
bfgpab asked this question in Q&A
Discussion options

You must be logged in to vote

I think you should put $userStore outside of onAuth method, like following untested code:

    import { getAuth, onAuthStateChanged } from "Firebase";
    import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'

    const $userStore = reactive({
        uid: 'foo',
    })

    // Check if user signed in
    onAuthStateChanged(auth, function ($result) {
        if ($result) {
            $userStore.uid = ????
        } else {
            window.location.replace("signin.html");
        };
    });


    createApp({
        // share it with app scopes
        $userStore,
        user: { id: $userStore.uid }
    }).mount()

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bfgpab
Comment options

Answer selected by bfgpab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants