Using getCurrentUser in global auth middle causes No Firebase App error #1388
-
Trying to follow the nuxt example and check for the current user in middleware but doing so causes this error: Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app). Here is my auth.global.ts middleware. import { getCurrentUser } from 'vuefire';
export default defineNuxtRouteMiddleware(async (to, from) => {
const user = await getCurrentUser();
// IF the user is going to the auth page and there is no user
if (to.path === '/' && !user) {
return;
}
if (!user) {
return navigateTo({
path: '/',
query: {
redirect: to.fullPath,
authMode: 'login',
},
});
}
}); I am using the GOOGLE_APPLICATION_CREDNETIALS env var with it being an object instead of a path to a serviceAccount json file. Any help would be appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Realized there was an issue with my appcheck config and the import of getCurrentUser, corrected my app check config and changed middleware to below, issue is gone. export default defineNuxtRouteMiddleware(async (to, from) => {
const user = await getCurrentUser();
// IF the user is going to the auth page and there is no auth user, let them go
if (to.path === '/' && !user) {
return;
}
// If no auth user and not going to auth page, redirect to auth page, with redirect query
if (!user) {
return navigateTo({
path: '/',
query: {
redirect: to.fullPath,
authMode: 'login',
},
});
} else if (user && to.path === '/') {
return navigateTo({
path: '/dashboard',
});
}
}); |
Beta Was this translation helpful? Give feedback.
Realized there was an issue with my appcheck config and the import of getCurrentUser, corrected my app check config and changed middleware to below, issue is gone.