nuxt-vuefire http://localhost:3000/api/__session 401 (Unauthorized) on production
ı'm trying to create a nuxt-vuefire app with ssr capability. It works on dev mode but when i build project and serve via node, firebase admin cannot initialize.
login.vue
async function handleLogin() {
useLoading().showLoading();
if (!validateForm()) return;
try {
// Set persistence based on "remember me" checkbox
if (rememberMe.value) {
await setPersistence(auth, browserLocalPersistence);
} else {
await setPersistence(auth, browserSessionPersistence);
}
const userCredential = await signInWithEmailAndPassword(auth, email.value, password.value);
const firebaseUser = userCredential.user;
// Redirect to home page
router.push('/');
} catch (error) {
validationErrors.value.email = {
hasError: true,
message: 'Kullanıcı adı veya şifre hatalı'
};
console.error('Login error:', error);
} finally {
useLoading().hideLoading();
}
}
nuxt.config.js
vuefire: {
auth: {
enabled: true,
sessionCookie: true
},
admin: {
serviceAccount: {
projectId: process.env.FIREBASE_PROJECT_ID,
clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
// Handle base64 encoded key for better environment compatibility
privateKey: process.env.FIREBASE_ADMIN_PRIVATE_KEY?.replace(/\\n/g, '\n')
}
},
config: {
apiKey: process.env.VITE_FIREBASE_API_KEY,
authDomain: process.env.VITE_FIREBASE_AUTH_DOMAIN,
projectId: process.env.VITE_FIREBASE_PROJECT_ID,
storageBucket: process.env.VITE_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.VITE_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.VITE_FIREBASE_APP_ID,
measurementId: process.env.VITE_FIREBASE_MEASUREMENT_ID
}
},
nitro: {
serverAssets: [
{
baseName: 'config',
dir: './',
include: ['service-account.json']
}
]
},login.vue
async function handleLogin() {
useLoading().showLoading();
if (!validateForm()) return;
try {
// Set persistence based on "remember me" checkbox
if (rememberMe.value) {
await setPersistence(auth, browserLocalPersistence);
} else {
await setPersistence(auth, browserSessionPersistence);
}
const userCredential = await signInWithEmailAndPassword(auth, email.value, password.value);
const firebaseUser = userCredential.user;
// Redirect to home page
router.push('/');
} catch (error) {
validationErrors.value.email = {
hasError: true,
message: 'Kullanıcı adı veya şifre hatalı'
};
console.error('Login error:', error);
} finally {
useLoading().hideLoading();
}
}
