Learn how to integrate Firebase Auth with Vue.js. This step-by-step guide shows you how to set up Firebase, configure auth, and manage user sign in/out in your app.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up a Firebase Project
Step 2: Configure Firebase for a Web App
</>).
Step 3: Set Up Your Vue.js Project
Ensure that Node.js and npm are installed on your computer.
Open terminal or command prompt.
Create a new Vue.js project with Vue CLI:
$ vue create firebase-auth-app
Navigate into your project directory:
$ cd firebase-auth-app
Install Firebase:
$ npm install firebase
Step 4: Initialize Firebase in Your Vue.js Project
In your project, create a new file firebase.js in the src directory.
Open firebase.js and add the Firebase config snippet obtained from your Firebase console:
import firebase from 'firebase/app';import 'firebase/auth';
const firebaseConfig = {
apiKey: "your-api-key",
authDomain: "your-auth-domain",
projectId: "your-project-id",
storageBucket: "your-storage-bucket",
messagingSenderId: "your-messaging-sender-id",
appId: "your-app-id"
};
firebase.initializeApp(firebaseConfig);
export const auth = firebase.auth();
Step 5: Set Up Authentication in Your Vue Application
Open main.js and import the Firebase configuration:
import Vue from 'vue';import App from './App.vue';
import { auth } from './firebase';
Vue.config.productionTip = false;
new Vue({
render: h => h(App),
created() {
auth.onAuthStateChanged(user => {
if (user) {
console.log('User is signed in:', user);
} else {
console.log('No user signed in.');
}
});
}
}).$mount('#app');
Use your Vue component to allow users to sign up or log in:
<template> <div>
<h1>Firebase Auth with Vue</h1>
<input v-model="email" placeholder="Email"/>
<input v-model="password" placeholder="Password" type="password"/>
<button @click="signUp">Sign Up</button>
<button @click="logIn">Log In</button>
<button @click="logOut">Log Out</button>
</div>
</template>
<script>
import { auth } from '@/firebase';
export default {
data() {
return {
email: '',
password: ''
};
},
methods: {
async signUp() {
try {
const userCredential = await auth.createUserWithEmailAndPassword(this.email, this.password);
console.log('User signed up:', userCredential.user);
} catch (error) {
console.error('Error signing up:', error);
}
},
async logIn() {
try {
const userCredential = await auth.signInWithEmailAndPassword(this.email, this.password);
console.log('User logged in:', userCredential.user);
} catch (error) {
console.error('Error logging in:', error);
}
},
async logOut() {
try {
await auth.signOut();
console.log('User logged out');
} catch (error) {
console.error('Error logging out:', error);
}
}
}
};
</script>
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.