{
    "componentChunkName": "component---src-templates-blog-post-js",
    "path": "/email-authentication-with-firebase-in-nodejs/",
    "result": {"data":{"site":{"siteMetadata":{"title":"CrewCode Solutions"}},"markdownRemark":{"id":"8882478b-dd67-5981-bdf6-e9baee7c64c9","excerpt":"In this article i will explain you step by step how you can add email authentication with firebase in your nodejs application Step 1: Create a Firebase Project…","html":"<p>In this article i will explain you step by step how you can add email authentication with firebase in your nodejs application</p>\n<h4>Step 1: Create a Firebase Project or you can skip this step of you have already created your firebase project</h4>\n<ul>\n<li>\n<p>Go to <a href=\"https://firebase.google.com\">https://firebase.google.com</a> and click on Get Started</p>\n</li>\n<li>\n<p>Proceed to click on Create a project.</p>\n</li>\n<li>\n<p>Enter a project name and check yes if you wish to add analytics to your project.</p>\n</li>\n<li>\n<p>Wait for the project to be created.</p>\n</li>\n</ul>\n<h4>Step 2: Create firebase credentials</h4>\n<ul>\n<li>\n<p><strong><em>Once your project created go to ProjectOverview->Project Settings and scroll below and click on Add App</em></strong></p>\n</li>\n<li>\n<p><strong><em>Select Web option</em></strong></p>\n</li>\n</ul>\n<p><img src=\"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/Email-auth-with-firebase-Node-1.png\" alt=\"firebase-add-app\"></p>\n<p><img src=\"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/Email-auth-with-firebase-Node-2.png\" alt=\"firebase-add-app\"></p>\n<p>Keep you credentials somewhere safe</p>\n<p><img src=\"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/Email-auth-with-firebase-Node-3.png\" alt=\"firebase-credentials\"></p>\n<h4>Step 3: Enable email authentication from firebase</h4>\n<p>In order to enable email authentication from firebase</p>\n<ul>\n<li>\n<p>Go to Authentication from left panel of firebase</p>\n</li>\n<li>\n<p>Go to sign-in method tab</p>\n</li>\n<li>\n<p>Click on Add new provider</p>\n</li>\n<li>\n<p>Select Email/Password and we are done</p>\n</li>\n</ul>\n<h4>Step 4: Add firebase authentication code to firebase</h4>\n<ul>\n<li><strong><em>Install firebase</em></strong></li>\n</ul>\n<p>Go to your node project folder and install firebase</p>\n<pre><code class=\"language-js\">npm install firebase\n</code></pre>\n<ul>\n<li><strong><em>Copy paste the following code in your node js project and according to your node js project setup</em></strong></li>\n</ul>\n<pre><code class=\"language-js\">import express from \"express\";\nimport path from \"path\";\nimport \"dotenv/config\";\nimport { initializeApp } from \"firebase/app\";\nconst app = express();\nconst port = 3000;\nconst __dirname = path.resolve();\nconst firebaseConfig = {\n  apiKey: process.env.API_KEY,\n  authDomain: process.env.AUTH_DOMAIN,\n  databaseURL: process.env.DATABASE_URL,\n  projectId: process.env.PROJECT_ID,\n  storageBucket: process.env.STORAGE_BUCKET,\n  messagingSenderId: process.env.MESSAGE_SENDER_ID,\n  appId: process.env.APP_ID,\n};\nconst firebase = initializeApp(firebaseConfig);\n\napp.use(express.json());\n\napp.use(express.static(path.join(__dirname, \"src/public\")));\n\napp.get(\"/login\", (req, res, next) => {\n  res.sendFile(__dirname + \"/src/public/index.html\");\n});\n\napp.post(\"/signup\", async (req, res, next) => {\n  var email = req.body.email;\n  var password = req.body.password;\n\n  firebase\n    .auth()\n    .createUserWithEmailAndPassword(email, password)\n    .then(function (userRecord) {\n      console.log(\"User Created\");\n    })\n    .catch(function (error) {\n      console.log(\"Something went wrong\");\n    });\n});\n\napp.post(\"/authenticate\", async (req, res, next) => {\n  var email = req.body.email;\n  var password = req.body.password;\n  firebase\n    .auth()\n    .signInWithEmailAndPassword(email, password)\n    .catch(function (error) {\n      console.log(error.code);\n      console.log(error.message);\n    });\n});\n\napp.post(\"/logout\", async (req, res, next) => {\n  firebase\n    .auth()\n    .signOut()\n    .then(\n      function () {\n        console.log(\"Logged out!\");\n      },\n      function (error) {\n        console.log(error.code);\n        console.log(error.message);\n      }\n    );\n});\n\napp.listen(port, () => {\n  console.log(`Demo app listening on port ${port}`);\n});\n</code></pre>","fields":{"slug":"/email-authentication-with-firebase-in-nodejs/"},"frontmatter":{"title":"Email authentication with firebase in nodejs","date":"September 01, 2022","description":"In this article i will explain you step by step how you can add email authentication with firebase in your nodejs application","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/email-authentication-firebase-nodejs.jpeg"}},"previous":{"fields":{"slug":"/email-authentication-flutter-firebase/"},"frontmatter":{"title":"Email authentication with firebase in flutter android and ios","date":"August 30, 2022","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/email-authentication-firebase.jpeg"}},"next":{"fields":{"slug":"/google-authentication-firebase-react-native/"},"frontmatter":{"title":"Google authentication with firebase in react native android application","date":"September 10, 2022","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/google-authentication-reactnative.jpeg"}}},"pageContext":{"id":"8882478b-dd67-5981-bdf6-e9baee7c64c9","previousPostId":"b99f15e4-45cb-5600-8953-203980b1866c","nextPostId":"82f31d34-4583-5b2a-aa39-370f32173ccb"}},
    "staticQueryHashes": ["3860684146"]}