Skip to content
Augusto Crespo edited this page Jul 8, 2021 · 4 revisions

The main goal of this document is to provide developer a tutorial of how to configure some parts of the site.

Single sign-on with Google (Authentication)

Requirements:

  • A Firebase project created with Google sign-in method activated
  • Firebase installed in the project

Method

  1. Create a firebase.js file

    1. Import Firebase and firebase auth module
    2. Create the const firebaseConfigu with all credentials required in your project: apiKey, authDomain, projectId, etc.
    3. Initialize firebase and create the var provider: firebase.initializeApp(firebaseConfig); var provider = new firebase.auth.GoogleAuthProvider();
    4. Export firebase and provider
  2. In Vue component

    1. Import the firebase.js file created before
    2. Create a method signInWithPopup calling the function firebase .auth() .signInWithPopup(provider) .then((result) => { this.credential = result.credential; // This gives you a Google Access Token. You can use it to access the Google API. this.token = this.credential.accessToken; // The signed-in user info. this.user = result.user; }) .catch((error) => { // Handle Errors here. });

In order to create user roles such as "admin", Firebase does not support this directly, but it allows to set custom user claims. We managed this through backend. More info at: https://dev.to/emeka/securing-your-express-node-js-api-with-firebase-auth-4b5f

Clone this wiki locally