Coder Social home page Coder Social logo

firenode's Introduction

nodeFire with Mongo Authorization

AngularFire with token authentication on Node backend server. This branch uses the mongoose node module with a mongo database to show an authorization example.

Get Started with nodeFire

  1. Run these commands to add the project locally:
$ git clone https://github.com/LukeSchlangen/nodeFire
$ cd nodeFire
$ git checkout mongo-authorization
$ npm install
  1. Create a free Firebase account at https://firebase.google.com

  2. Create a project from your Firebase account console

  3. Add a connection to firebase on your front end

  4. Click the “Add Firebase to your web app” icon

  5. Copy the contents WITHOUT SCRIPT TAGS or the CDN from the resulting popup into public/config.js. It should look like this:

```javascript
  // Initialize Firebase
  var config = {
    apiKey: "XXXXXXXXXXXXXXXXXXXXXX",
    authDomain: "XXXXXXXXXXXX.firebaseapp.com",
    databaseURL: "https://XXXXXXXXXXXX.firebaseio.com",
    storageBucket: "XXXXXXXXXXXX.appspot.com",
    messagingSenderId: "XXXXXXXXXX"
  };
  firebase.initializeApp(config);
```
  1. Add a firebase service account to you node project
  2. Navigate to the Service Accounts tab in your project's settings page.
  3. Select your Firebase project.
  4. Copy your databaseURL from the Admin SDK configuration snippet. The line you need will look like this: databaseURL: "https://XXXXXXXXX.firebaseio.com".
  5. Navigate to the server/modules/decoder.js file in the node project and replace the databaseURL. Only replace that line. It is inside of the admin.initializeApp:
```javascript
admin.initializeApp({
  credential: admin.credential.cert("./server/firebase-service-account.json"),
  databaseURL: "https://XXXXXXXXX.firebaseio.com" // replace this line with your URL
});
```
  1. Return to firebase Service Accounts. Navigate to your project again if you have left it.

  2. Click the Generate New Private Key button at the bottom of the Firebase Admin SDK section of the Service Accounts tab.

  3. Rename the new JSON file to firebase-service-account.json and save it in the server folder of your application.

  4. Return to Firebase console. Configure Google as an authentication provider for your Firebase project.

  5. In the Firebase console for your project (you may already be there from the previous step), click "Authentication" in left panel

  6. Click "Set Up Sign-In Method" button

  7. Select "Google"

  8. Click the "edit" icon

  9. Toggle Google to on

  10. Connect the application to your database

  11. Create a new mongo database or select one you already use. In server/modules/database-config.js, change the connection string, currently var connectionString = 'postgres://localhost:5432/sigma';, to match the location of your database.

  12. Copy the queries from the database.js file and run them in robomongo or the mongo terminal to create the necessary collections for this project. On the db.users.insert, be sure to add your own name and give yourself a clearance_level from 1 to 5. This will determine what data you can see:

```javascript
db.users.insert(
   [
    { email: '[email protected]', clearanceLevel: 5 },
    { email: '[email protected]', clearanceLevel: 4 }, // Your Google Email added here
    { email: '[email protected]', clearanceLevel: 2 }, // Your Other Google Email added here
    { email: '[email protected]', clearanceLevel: 3 }
   ]
);
```

Because you have set up google OAuth, you will need to log in with a google account (an email with @gmail.com will work great). If you have a second google account, that will make it easy to see the differences for people with differing clearance levels.

  1. Run npm start to run your application on localhost:5000

Contributing

  1. The repository is open to contribution from all interested developers. Kindly send us Pull Requests with explanation as to what changes you have done.
  2. Also, you can write to us by opening an Issue and also solve a current issue if possible.

License

  1. The software is registered under the MIT License

firenode's People

Contributors

airwolff avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.