What's the right way to use VueFire witn Nuxt SSG? #1467
-
This is my page <template>
<main class="min-h-screen bg-gray-50">
<AppNavbar />
<AppPageLoading v-if="!user" label="Authenticating" subtitle="Please wait..." />
<NuxtPage v-else />
</main>
</template>
<script setup>
definePageMeta({
middleware: ["authenticated"]
});
const { getCountryCode } = useLocalization();
const { data: user } = await useAsyncData("init", async () => {
try {
const user = await getCurrentUser();
if (user) {
// Set firebase token in state
const idToken = await user.getIdToken();
useState("idToken", () => idToken);
getCountryCode();
// Get user details
const { data, error } = await useApi("/user/details");
if (error.value) throw error;
if (!data.value.success) throw new Error("User not found");
useState("userDetails", () => data);
return data;
} else {
console.log("No authenticated user found.");
}
} catch (error) {
console.log(error);
}
});
</script> This is my middleware
I feel like I am doing this correctly, yet somehow I get this logged in the console
And Once the Note: Nothing is breaking, but the error is making me feel I am not doing it correctly. @posva Any suggestion/insights? |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Nov 30, 2023
Replies: 1 comment
-
Composables should all go before the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Composables should all go before the
await
. But you also don't need it, you can useuseCurrentUser()
. You can watch its value with a watcher too.