<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ryan </title>
    <description>The latest articles on DEV Community by Ryan  (@ryanaz).</description>
    <link>https://dev.to/ryanaz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F132947%2F42c71dc3-0f5e-4bde-8102-a3e9bbeab651.jpg</url>
      <title>DEV Community: Ryan </title>
      <link>https://dev.to/ryanaz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ryanaz"/>
    <language>en</language>
    <item>
      <title>🍝 Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe - 🚀 Bonus: deploy - part 7/7)</title>
      <dc:creator>Ryan </dc:creator>
      <pubDate>Mon, 04 Feb 2019 02:51:40 +0000</pubDate>
      <link>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e</link>
      <guid>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbsm0q2edt1uhnn5r5jmv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbsm0q2edt1uhnn5r5jmv.png" alt="Strapi Next.js tutorial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This tutorial is part of the « Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe » tutorial series.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of contents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏗️ &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----setup-part-17-ked"&gt;Setup&lt;/a&gt; (part 1) &lt;/li&gt;
&lt;li&gt;🏠 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce"&gt;Restaurants&lt;/a&gt; (part 2)&lt;/li&gt;
&lt;li&gt;🍔 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh/"&gt;Dishes&lt;/a&gt; (part 3)&lt;/li&gt;
&lt;li&gt;🔐 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho"&gt;Authentication&lt;/a&gt; (part 4)&lt;/li&gt;
&lt;li&gt;🛒 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e"&gt;Shopping Cart&lt;/a&gt; (part 5)&lt;/li&gt;
&lt;li&gt;💵 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph"&gt;Order and Checkout&lt;/a&gt; (part 6)&lt;/li&gt;
&lt;li&gt;🚀 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e"&gt;Bonus: Deploy&lt;/a&gt; (part 7) - &lt;strong&gt;current&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note: the **source code&lt;/em&gt;* is &lt;strong&gt;available on GitHub&lt;/strong&gt;: &lt;a href="https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*" rel="noopener noreferrer"&gt;https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 Bonus: deploy
&lt;/h2&gt;

&lt;p&gt;At this point, we only need to deploy our API and our web app.&lt;br&gt;
Strpi can be hosted on any major provider offering node deployments (AWS, Heroku, DO). Read further about deployment of Strapi here:&lt;br&gt;
&lt;a href="https://strapi.io/documentation/3.x.x/guides/deployment.html" rel="noopener noreferrer"&gt;https://strapi.io/documentation/3.x.x/guides/deployment.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: for deployment you will need to change your URLs and connection strings from the default localhost:1337 we were using in the tutorial to the absolute server URL your deploying to.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In a real world application, it would be advised to use webpack environment variables to prevent having to manually change the URL every time you deploy to production&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Bonus:Bonus AWS File Upload
&lt;/h3&gt;

&lt;p&gt;If deploying your backend to a provider that does not persist storage on the server like Heroku, the default Strapi local server upload will not work as your files on the server are automatically wiped periodically.&lt;/p&gt;

&lt;p&gt;Strapi does supports easy file upload to S3, to enable it follow the instructions below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strapi Docs:&lt;/strong&gt; &lt;a href="https://strapi.io/documentation/3.x.x/guides/upload.html#examples" rel="noopener noreferrer"&gt;https://strapi.io/documentation/3.x.x/guides/upload.html#examples&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To install the strapi-aws-upload package go to the root of your folder you created Strapi in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd backend
npm install strapi-upload-aws-s3@alpha --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After the package is installed you can navigate in your browser to:&lt;br&gt;
&lt;a href="http://localhost:1337/admin/plugins/upload/configurations/development" rel="noopener noreferrer"&gt;http://localhost:1337/admin/plugins/upload/configurations/development&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should see configuration options for your file upload storage options for the respective environment&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbk781femukljrxe5hzbi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbk781femukljrxe5hzbi.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select Amazon Web Service S3 from the &lt;em&gt;Provider&lt;/em&gt; dropdown&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3woce7hdyyzbac7cgohe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3woce7hdyyzbac7cgohe.png" alt="image2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enter your respective AWS Access Key ID, Secret, Region and Bucket name, also make sure the enable file upload is flipped to ON&lt;/p&gt;

&lt;p&gt;In the frontend code, make sure to remove the localhost:1337 from your img src attribute. You can now just use  &lt;strong&gt;res.image.url&lt;/strong&gt; to grab the S3 image link&lt;/p&gt;

&lt;p&gt;You will have to do this for both the &lt;code&gt;RestaurantList index.js&lt;/code&gt; component and &lt;code&gt;restaurants.js&lt;/code&gt; page&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
 &lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Thats all it takes to enable S3 file uploads with Strapi!&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Backend
&lt;/h3&gt;

&lt;p&gt;Init a git project and commit your files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd backend
rm package-lock.json # May involved errors if not removed
git init
git add .
git commit -am "Initial commit"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Make sure the &lt;a href="https://devcenter.heroku.com/articles/heroku-cli#download-and-install" rel="noopener noreferrer"&gt;Heroku CLI is installed&lt;/a&gt; on your computer and deploy:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku create
heroku addons:create mongolab:sandbox --as DATABASE
git push heroku master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0c9ar3aweiugy9t6100q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0c9ar3aweiugy9t6100q.png" alt="Heroku deploy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To get Strapi working on Heroku you will need to set your database connection strings:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Login to Heroku, navigate you the newly app created.&lt;br&gt;
YourApp -&amp;gt; Settings -&amp;gt; Reveal Config Var&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fofue5npb9zrcv6vuyync.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fofue5npb9zrcv6vuyync.png" alt="Heroku"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will need to add these config variables in order for Strapi to connect to the DB.&lt;/p&gt;

&lt;p&gt;These config variables can be deconstructed from the standard DATABASE_URI value you will see on this page.&lt;/p&gt;

&lt;p&gt;Create new values breaking down the connection string as followed below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fujdczkbnzba6zhys9p7q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fujdczkbnzba6zhys9p7q.png" alt="Config Vars"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: your values will differ from these, but be similar structure:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DATABASE_AUTHENTICATION_DATABASE&lt;/code&gt; = value starting with heroku_ all the way to the colon of your string &lt;strong&gt;(i.e. heroku_2dcnd31p)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DATABASE_NAME&lt;/code&gt; = same as &lt;code&gt;DATABASE_AUTHENTICATION_DATABASE&lt;/code&gt; &lt;strong&gt;(i.e. heroku_2dcnd31p)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DATABASE_HOST&lt;/code&gt; = string starting with ds followed by numbers ending in .mlab.com &lt;strong&gt;(i.e. ds244132.mlab.com)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DATABASE_PORT&lt;/code&gt; = 5 digits following the colon of the host name &lt;strong&gt;(i.e. 25432)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DATABASE_USERNAME&lt;/code&gt; = same as DATABASE_NAME&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DATABASE_PASSWORD&lt;/code&gt; = random character string after colon of the DATABASE_USERNAME, all the way to the @ sign&lt;/p&gt;

&lt;p&gt;You can view your Strapi backend by visiting the URL/route provided by heroku &lt;code&gt;/admin&lt;/code&gt; (&lt;a href="https://yourapp.com/admin" rel="noopener noreferrer"&gt;https://yourapp.com/admin&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: you will have to redefine your permissions rules from the interface. This workflow will be &lt;a href="https://github.com/strapi/strapi/issues/672" rel="noopener noreferrer"&gt;improved in the near future&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Next Deployment
&lt;/h3&gt;

&lt;p&gt;You can easily host your front end on Heroku as well. You will need to modify your packages.json file to add in a heroku-postbuild option that will be run once the code is deployed to start your app. You can also add in the &lt;code&gt;-p $PORT&lt;/code&gt;flag to your start command&lt;/p&gt;

&lt;p&gt;Modify the scripts section if your &lt;code&gt;packages.json&lt;/code&gt; file to match:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;packages.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "NODE_ENV=production node server.js -p $PORT",
    "heroku-postbuild": "next build"
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Heroku assigns a port dynamically, this is accessible from &lt;code&gt;process.env.PORT&lt;/code&gt;. We will need to tell our express server to listen on this port or the default assigned 3000 port. &lt;/p&gt;

&lt;p&gt;This will allow us to run locally on port 3000 and in production to the dynamically assigned Heroku port.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;process.env.PORT || 3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Full &lt;code&gt;server.js&lt;/code&gt; file:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Now create the git repo for the frontend:&lt;/p&gt;

&lt;p&gt;Init a git project and commit your files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd frontend
rm package-lock.json # May involved errors if not removed
git init
git add .
git commit -am "Initial commit"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then deploy to Heroku:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku create
git push heroku master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your command line should show the URL for the application where you can view your app!&lt;/p&gt;




&lt;p&gt;Extra:&lt;/p&gt;

&lt;h2&gt;
  
  
  NOW serverless deployment:
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;only follow if you want to deploy your next project as a static build site without custom routing/logic&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: The following deployment method will only deploy your project as a static hosted site on the NOW serverless platform. Your custom express server will not be created following this method. *leaving in for reference if needed for your needs&lt;/strong&gt;*&lt;/p&gt;

&lt;p&gt;You can host next projects anywhere a node project can be deployed as it is just a node pacakage. For this tutorial we will deploy to NOW, a serverless deployment provider:&lt;br&gt;
&lt;a href="https://zeit.co/now" rel="noopener noreferrer"&gt;https://zeit.co/now&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Init a git project and commit your files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd frontend
rm package-lock.json # May involved errors if not removed
git init
git add .
git commit -am "Initial commit"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First install the NOW command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g now
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow the instructions to confirm your email.&lt;/p&gt;

&lt;p&gt;Add the following Dockerfile which will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install all the dependencies&lt;/li&gt;
&lt;li&gt;Build the application for production&lt;/li&gt;
&lt;li&gt;Remove non-production dependencies&lt;/li&gt;
&lt;li&gt;Create a new lighter Docker image to reduce boot time&lt;/li&gt;
&lt;li&gt;Pull built files and production dependencies from previous steps&lt;/li&gt;
&lt;li&gt;Expose the port 300 and run the application&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Create the Dockerfile at the root of the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch Dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM mhart/alpine-node:10 as base
WORKDIR /usr/src
COPY package.json yarn.lock /usr/src/
RUN yarn install
COPY . .
RUN yarn build &amp;amp;&amp;amp; yarn --production

FROM mhart/alpine-node:base-10
WORKDIR /usr/src
ENV NODE_ENV="production"
COPY --from=base /usr/src .
EXPOSE 3000
CMD ["node", "./node_modules/.bin/next", "start"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, create a &lt;code&gt;now.json&lt;/code&gt; file at the root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch now.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "type": "docker",
  "public": true,
  "features": {
    "cloud": "v2"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run command &lt;code&gt;now&lt;/code&gt; for deployment&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Huge congrats, you successfully achieved this tutorial. I hope you enjoyed it!&lt;/p&gt;

&lt;p&gt;The source code is available on GitHub: &lt;a href="https://github.com/ryanbelke/strapi-next" rel="noopener noreferrer"&gt;https://github.com/ryanbelke/strapi-next&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Still hungry?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Feel free to add additional features, adapt this projects to your own needs and give your feedback in the comments section.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Share your meal!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You enjoyed this tutorial? Share it around you!&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🍝 Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe - 💵 Order and Checkout (part 6/7)</title>
      <dc:creator>Ryan </dc:creator>
      <pubDate>Mon, 04 Feb 2019 02:49:52 +0000</pubDate>
      <link>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph</link>
      <guid>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fo43jprp2ehbd5qyo5106.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fo43jprp2ehbd5qyo5106.png" alt="Strapi Next.js tutorial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This tutorial is part of the « Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe » tutorial series.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of contents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏗️ &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----setup-part-17-ked"&gt;Setup&lt;/a&gt; (part 1) &lt;/li&gt;
&lt;li&gt;🏠 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce"&gt;Restaurants&lt;/a&gt; (part 2)&lt;/li&gt;
&lt;li&gt;🍔 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh/"&gt;Dishes&lt;/a&gt; (part 3)&lt;/li&gt;
&lt;li&gt;🔐 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho"&gt;Authentication&lt;/a&gt; (part 4)&lt;/li&gt;
&lt;li&gt;🛒 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e"&gt;Shopping Cart&lt;/a&gt; (part 5)&lt;/li&gt;
&lt;li&gt;💵 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph"&gt;Order and Checkout&lt;/a&gt; (part 6) &lt;strong&gt;- current&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🚀 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e"&gt;Bonus: Deploy&lt;/a&gt; (part 7) - &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: the &lt;strong&gt;source code&lt;/strong&gt; is &lt;strong&gt;available on GitHub&lt;/strong&gt;: &lt;a href="https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*" rel="noopener noreferrer"&gt;https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  💵 Order and Checkout
&lt;/h2&gt;

&lt;p&gt;You must start being starving... I am sure you want to be able to order!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8bf6tg40xioe9jzenr83.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8bf6tg40xioe9jzenr83.gif" alt="Order"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Define Content Type
&lt;/h3&gt;

&lt;p&gt;We need to store the orders in our database, so we are going to create a new Content Type in our API.&lt;/p&gt;

&lt;p&gt;Same process as usual:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the Content Type Builder (&lt;a href="http://localhost:1337/admin/plugins/content-type-builder" rel="noopener noreferrer"&gt;http://localhost:1337/admin/plugins/content-type-builder&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Add Content Type&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;order&lt;/code&gt; as name.&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Add New Field&lt;/code&gt; and create the followings fields:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;address&lt;/code&gt; with type &lt;code&gt;String&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;city&lt;/code&gt; with type &lt;code&gt;String&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dishes&lt;/code&gt; with type &lt;code&gt;JSON&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;amount&lt;/code&gt; with type &lt;code&gt;Integer&lt;/code&gt; (decimal).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Click on Save.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4ahcuy3dyh635z14in2u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4ahcuy3dyh635z14in2u.png" alt="Order Content Type Builder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Allow access
&lt;/h3&gt;

&lt;p&gt;To create new orders from the client, we are going to hit the &lt;code&gt;create&lt;/code&gt; endpoint of the &lt;code&gt;order&lt;/code&gt; API. To allow access, navigate to the Roles &amp;amp; Permissions section (&lt;a href="http://localhost:1337/admin/plugins/users-permissions" rel="noopener noreferrer"&gt;http://localhost:1337/admin/plugins/users-permissions&lt;/a&gt;), select the &lt;code&gt;authenticated&lt;/code&gt; role, tick the &lt;code&gt;order/create&lt;/code&gt; checkbox and save.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stripe setup
&lt;/h3&gt;

&lt;p&gt;In this section you will need Stripe API keys. To get them, create a Stripe account and navigate to &lt;a href="https://dashboard.stripe.com/account/apikeys" rel="noopener noreferrer"&gt;https://dashboard.stripe.com/account/apikeys&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add logic
&lt;/h3&gt;

&lt;p&gt;If you already used Stripe, you probably know the credit card information does not go through your backend server. Instead, the credit card information is sent to the Stripe API (ideally using their SDK). Then, your frontend receives a token that can be used to charge credit cards. The &lt;code&gt;id&lt;/code&gt; must be sent to your backend which will create the Stripe charge.&lt;/p&gt;

&lt;p&gt;Not passing the credit card information through your server relieves you the responsibility to meet complicated data handling compliance, and is just far easier than worrying about securely storing sensitive data.&lt;/p&gt;

&lt;p&gt;In order to integrate the Stripe logic, we need to update the &lt;code&gt;create&lt;/code&gt; charge endpoint in our Strapi API. To do so, edit &lt;code&gt;backend/api/order/controllers/order.js&lt;/code&gt; and replace its content with:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Path: &lt;code&gt;/backend/api/order/controllers/order.js&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Note: in a real-world example, the amount should be checked on the backend side and the list of dishes related to the command should be stored in a more specific Content Type called &lt;code&gt;orderDetail&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Install the &lt;code&gt;stripe&lt;/code&gt; package inside the backend directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd ..
cd ..
cd backend 
npm i stripe --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Do not forget to restart the Strapi server.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: if an error occurs, run &lt;code&gt;npm i strapi-hook-mongoose&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To interact with the Stripe API, we will use the &lt;a href="https://github.com/stripe/react-stripe-elements" rel="noopener noreferrer"&gt;react-stripe-elements&lt;/a&gt; which will give us a StripeProvider and Elements components to style our credit card form and submit the information properly to Stripe.&lt;/p&gt;
&lt;h3&gt;
  
  
  Checkout page
&lt;/h3&gt;

&lt;p&gt;Create a new page: &lt;code&gt;pages/checkout.js/&lt;/code&gt;,&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd frontend
yarn add react-stripe-elements
cd pages
touch checkout.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Path: &lt;code&gt;/frontend/pages/checkout.js&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;






&lt;p&gt;Now we are going to create the checkout form and card section component to capture the credit card info and pass it to Stripe using the react-stripe-elements package:&lt;/p&gt;

&lt;p&gt;Create the checkout form files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd components
mkdir Checkout
cd Checkout
touch CheckoutForm.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Path: &lt;code&gt;/frontend/components/Checkout/CheckoutForm.js&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Now create a &lt;code&gt;CardSection.js&lt;/code&gt; file to use the React Elements in, this will house the input boxes that will capture the CC information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch CardSection.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Path: &lt;code&gt;/frontend/components/Checkout/CardSection.js&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Now if you select a dish and click order you should see:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkzzgwbnj8a1627jimffa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkzzgwbnj8a1627jimffa.png" alt="CheckoutPicture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if you submit your order, you should see the order under the Strapi dashboard as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwjby2kfqnnpp3ro1dknl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwjby2kfqnnpp3ro1dknl.png" alt="Strapi"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanations 🕵️&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Note: explanations of code samples only, do not change your code to match this as you should already have this code this is simply a snippet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For server side rendering with &lt;a href="https://github.com/stripe/react-stripe-elements" rel="noopener noreferrer"&gt;react-stripe elements&lt;/a&gt;, some modifications need to be made as Stripe will only be available on the client not the server.&lt;/p&gt;

&lt;p&gt;To account for this, the stripe pk_key is set in the ComponentDidMount lifecycle hook that only fires on the browser:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Stripe will use a &lt;code&gt;&amp;lt;StripeProvider&amp;gt;&lt;/code&gt; component that will take in your stripe pk_key as a prop. This allows the children of the component access to the stripe key.&lt;/p&gt;

&lt;p&gt;To use the integrated stripe components we will wrap our CheckoutForm component in the &lt;code&gt;&amp;lt;Elements&amp;gt;&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;The downstream &lt;code&gt;import { injectStripe } from "react-stripe-elements"&lt;/code&gt; inside the CheckoutForm component is required for the Elements children components to pass the CC information to Stripe. &lt;/p&gt;

&lt;p&gt;Stripe will automatically detect which components are generating the CC information and what information to send to receive the token.&lt;/p&gt;

&lt;p&gt;This submitOrder function will first make the call to Stripe with the CC information and receive back the Token if the CC check passed. If the token is received we next call the Strapi SDK to create the order passing in the appropriate information and token id.&lt;/p&gt;

&lt;p&gt;This is what creates the order in Stripe and creates the DB entry in Strapi. If successful you should see your Stripe test balances increase by the amount of the test order.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;You are now able to let users submit their order.&lt;/p&gt;

&lt;p&gt;Bon appétit! 🇫🇷&lt;/p&gt;

&lt;p&gt;🚀 In the next (and last) section, you will learn how to &lt;strong&gt;deploy your Strapi app on Heroku&lt;/strong&gt; and &lt;strong&gt;your frontend app on &lt;a href="https://zeit.co/now#get-started" rel="noopener noreferrer"&gt;NOW&lt;/a&gt;&lt;/strong&gt; : &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e"&gt;https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🍝 Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe - 🛒 Shopping cart (part 5/7)</title>
      <dc:creator>Ryan </dc:creator>
      <pubDate>Mon, 04 Feb 2019 02:48:01 +0000</pubDate>
      <link>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e</link>
      <guid>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg0ojkm8suwb37zgc0rbm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg0ojkm8suwb37zgc0rbm.png" alt="Strapi Next.js tutorial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This tutorial is part of the « Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe » tutorial series.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of contents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏗️ &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----setup-part-17-ked"&gt;Setup&lt;/a&gt; (part 1) &lt;/li&gt;
&lt;li&gt;🏠 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce"&gt;Restaurants&lt;/a&gt; (part 2)&lt;/li&gt;
&lt;li&gt;🍔 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh/"&gt;Dishes&lt;/a&gt; (part 3)&lt;/li&gt;
&lt;li&gt;🔐 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho"&gt;Authentication&lt;/a&gt; (part 4)&lt;/li&gt;
&lt;li&gt;🛒 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e"&gt;Shopping Cart&lt;/a&gt; (part 5) &lt;strong&gt;-current&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;💵 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph"&gt;Order and Checkout&lt;/a&gt; (part 6)&lt;/li&gt;
&lt;li&gt;🚀 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e"&gt;Bonus: Deploy&lt;/a&gt; (part 7) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note: the **source code&lt;/em&gt;* is &lt;strong&gt;available on GitHub&lt;/strong&gt;: &lt;a href="https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*" rel="noopener noreferrer"&gt;https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🛒 Shopping Cart
&lt;/h2&gt;

&lt;p&gt;All of these dishes look so tasty! What if we could add some of them in a shopping card?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl2susfttjxih2o0nr370.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl2susfttjxih2o0nr370.gif" alt="Shopping card"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we create a new component named &lt;code&gt;Cart.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd components
mkdir Cart
cd Cart
touch Cart.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Path: &lt;code&gt;/frontend/components/Cart/Cart.js&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  React Context
&lt;/h2&gt;

&lt;p&gt;To keep track of our items added to our cart across pages we will use the React Context API. Context will allow us to manage the state of items in a provider component that will be re-used on the checkout page. The only thing React Context will not take care of for us is saving items on a page refresh, for that you would want to save the items to a cookie and restore the items from the cookie. I will work to implement this soon if requested. &lt;/p&gt;

&lt;p&gt;The items are currently saved to a cookie called items, but the items are not restored on refresh.&lt;/p&gt;

&lt;p&gt;Create a new directory inside our components folder:&lt;/p&gt;

&lt;p&gt;Note: you can name your AppProvider anything related to the context you are storing (i.e. ItemsContextProvder). This would allow you to use and keep track of multiple providers/consumers throughout the app if your needs grow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
mkdir Context
cd Context
touch AppProvider.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Path: &lt;code&gt;/frontend/components/Context/AppProvider.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Now we will need to make some changes to use our Context throughout the application and on the dishes page. &lt;/p&gt;

&lt;p&gt;Update the &lt;code&gt;_app.js&lt;/code&gt; and &lt;code&gt;/pages/restaurants.js&lt;/code&gt; files to use the AppProvider/Consumer components:&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/pages/_app.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Path: &lt;code&gt;/frontend/pages/restaurants.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now if you refresh the page you should see the Cart component to the right of the dishes.&lt;/p&gt;

&lt;p&gt;Your Layout header should also update with the username of the logged in user and show a logout button if you are logged in.&lt;/p&gt;

&lt;p&gt;To actually place an order the &lt;code&gt;isAuthenticated&lt;/code&gt; prop must pass to true, in a real world app you would want to secure these routes on the server side rather than on the client side. Any props/state on the client can be altered and therefore should not expose real world data without server validation. &lt;/p&gt;

&lt;p&gt;For the sake of the tutorial we are not currently implementing this.&lt;/p&gt;

&lt;p&gt;Good job!&lt;/p&gt;

&lt;p&gt;💵 In the next section, you will learn how to &lt;strong&gt;setup Stripe for checkout and create orders&lt;/strong&gt;: &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph"&gt;https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🍝 Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe - 🔐 Authentication (part 4/7)</title>
      <dc:creator>Ryan </dc:creator>
      <pubDate>Mon, 04 Feb 2019 02:46:43 +0000</pubDate>
      <link>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho</link>
      <guid>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwuj0bbwm4jn31muigkgm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwuj0bbwm4jn31muigkgm.png" alt="Strapi Next.js tutorial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This tutorial is part of the « Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe » tutorial series.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of contents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏗️ &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----setup-part-17-ked"&gt;Setup&lt;/a&gt; (part 1) &lt;/li&gt;
&lt;li&gt;🏠 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce"&gt;Restaurants&lt;/a&gt; (part 2)&lt;/li&gt;
&lt;li&gt;🍔 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh/"&gt;Dishes&lt;/a&gt; (part 3)&lt;/li&gt;
&lt;li&gt;🔐 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho"&gt;Authentication&lt;/a&gt; (part 4) &lt;strong&gt;-current&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🛒 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e"&gt;Shopping Cart&lt;/a&gt; (part 5)&lt;/li&gt;
&lt;li&gt;💵 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph"&gt;Order and Checkout&lt;/a&gt; (part 6)&lt;/li&gt;
&lt;li&gt;🚀 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e"&gt;Bonus: Deploy&lt;/a&gt; (part 7) - &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note: the **source code&lt;/em&gt;* is &lt;strong&gt;available on GitHub&lt;/strong&gt;: &lt;a href="https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*" rel="noopener noreferrer"&gt;https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔐 Authentication
&lt;/h2&gt;

&lt;p&gt;For authentication, we can use the Strapi SDK to register and login our users. Strapi will return a JWT token that can be used to verify transactions on the server (although we will not setup server validation in this tutorial you should in a real world application).&lt;/p&gt;

&lt;p&gt;The strapi documentation on users can be found here: &lt;a href="https://strapi.io/documentation/1.x.x/users.html" rel="noopener noreferrer"&gt;https://strapi.io/documentation/1.x.x/users.html&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Authentication
&lt;/h3&gt;

&lt;p&gt;For authentication we are going to use 2 higher order components &lt;code&gt;defaultPage.js&lt;/code&gt; and &lt;code&gt;securePage.js&lt;/code&gt; to wrap our pages and pass an isAuthenticated prop down to the necesseray components.&lt;/p&gt;

&lt;p&gt;Make a new directory in the root of the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir hocs
cd hocs
touch defaultPage.js
touch securePage.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Path: &lt;code&gt;/frontend/components/hocs/defaultPage.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Path: &lt;code&gt;/frontend/components/hocs/securePage.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;To setup our authentication functions we will create a new file under the &lt;code&gt;/lib&lt;/code&gt; folder called &lt;code&gt;auth.js&lt;/code&gt; that will allow us to control and change authentication functionality in one place.&lt;/p&gt;

&lt;p&gt;As you will, three new dependencies are imported in the upcoming files, so you need to install them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
yarn add jwt-decode js-cookie strapi-sdk-javascript 

cd lib
touch auth.js


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Path: &lt;code&gt;/frontend/lib/auth.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why cookies? 🍪&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Nothing related to this food tutorial...&lt;/p&gt;

&lt;p&gt;Most of the time, progressive web apps store a JSON Web Token (JWT) in the local storage. That works pretty well, and this is what the Strapi JavaScript SDK does by default (it also stores it as a cookie).&lt;/p&gt;

&lt;p&gt;The fact is that we would like to display the username in the header (coming later in this tutorial). So we need to store it somewhere.&lt;/p&gt;

&lt;p&gt;We could have store it in the local storage, but since Nuxt supports server-side rendering, which has not access to the local storage, we need to store it in the cookies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Register
&lt;/h3&gt;

&lt;p&gt;To register a user we will pass a username, email and password with the Strapi SDK. This will register a user in Strapi and log the user in. Inside of our signup page we will call the strapiRegister function inside of our auth.js file to register the user then set the appropriate JWT and username cookies inside the browser.&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/pages/signup.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fthinngs0h3szqgi577hp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fthinngs0h3szqgi577hp.png" alt="auth"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Logout
&lt;/h3&gt;

&lt;p&gt;Inside of our &lt;code&gt;Layout.js&lt;/code&gt; component we check for an authenticated user using the isAuthenticated prop, and if a user is detected we display the username and a logout button.&lt;/p&gt;

&lt;p&gt;The logout button will call the unsetToken function to delete the cookies and re-route to the home page.&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/components/Layout.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Login
&lt;/h3&gt;

&lt;p&gt;Similar to our login page, the sign-in page will use the Strapi SDK to login in the user and set the appropriate username and JWT cookies for later use.&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/pages/signin.js&lt;/code&gt;&lt;br&gt;
 &lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fywxcbkycjuk7moumucwt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fywxcbkycjuk7moumucwt.png" alt="signin"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now update your &lt;code&gt;index.js&lt;/code&gt; page to use the newly created defaultPage HOC.&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/pages/index.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Next we wil setup React Context for our shopping cart, and allow our Layout header bar to recognize a user is logged in and display the username&lt;/p&gt;

&lt;p&gt;🛒 In the next section, you will learn how to &lt;strong&gt;create a full featured shopping cart&lt;/strong&gt;: &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e"&gt;https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🍝 Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe - 🍔 Dishes list (part 3/7)</title>
      <dc:creator>Ryan </dc:creator>
      <pubDate>Mon, 04 Feb 2019 02:45:41 +0000</pubDate>
      <link>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh</link>
      <guid>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fiudm6at0xp8v1o7f1f86.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fiudm6at0xp8v1o7f1f86.png" alt="Strapi Next.js tutorial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This tutorial is part of the « Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe » tutorial series.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of contents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏗️ &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----setup-part-17-ked"&gt;Setup&lt;/a&gt; (part 1) &lt;/li&gt;
&lt;li&gt;🏠 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce"&gt;Restaurants&lt;/a&gt; (part 2)&lt;/li&gt;
&lt;li&gt;🍔 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh/"&gt;Dishes&lt;/a&gt; (part 3) &lt;strong&gt;-current&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🔐 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho"&gt;Authentication&lt;/a&gt; (part 4)&lt;/li&gt;
&lt;li&gt;🛒 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e"&gt;Shopping Cart&lt;/a&gt; (part 5)&lt;/li&gt;
&lt;li&gt;💵 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph"&gt;Order and Checkout&lt;/a&gt; (part 6)&lt;/li&gt;
&lt;li&gt;🚀 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e"&gt;Bonus: Deploy&lt;/a&gt; (part 7) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note: the **source code&lt;/em&gt;* is &lt;strong&gt;available on GitHub&lt;/strong&gt;: &lt;a href="https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*" rel="noopener noreferrer"&gt;https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  🍔 Dishes list
&lt;/h2&gt;

&lt;p&gt;Congratulations, you successfully displayed the list of restaurants! This was the first major step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Define Content Type
&lt;/h3&gt;

&lt;p&gt;Every restaurant sells dishes, which also must be stored in the database. So, we now need a new Content Type, obviously named &lt;code&gt;dish&lt;/code&gt;. Since you already know how to create it, I am going to give only its attributes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;name&lt;/code&gt; with type &lt;code&gt;String&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;description&lt;/code&gt; with type &lt;code&gt;Text&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;image&lt;/code&gt; with type &lt;code&gt;Media&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;price&lt;/code&gt; with type &lt;code&gt;Number&lt;/code&gt; (integer).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;restaurant&lt;/code&gt; with type &lt;code&gt;Relation&lt;/code&gt;: this one is a bit more specific. Our purpose here is to tell to Strapi that every dish can be related to a restaurant. To do so, create a one-to-many relation, as below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fum51cjveo5xweophtze9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fum51cjveo5xweophtze9.png" alt="Strapi relation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the final result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fozxel8tagpyq9xfjc0a0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fozxel8tagpyq9xfjc0a0.png" alt="Dishes fields"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Add some entries
&lt;/h3&gt;

&lt;p&gt;Then, add some dishes from the Content Manager: &lt;a href="http://localhost:1337/admin/plugins/content-manager/dish" rel="noopener noreferrer"&gt;http://localhost:1337/admin/plugins/content-manager/dish&lt;/a&gt;. Make sure they all have an image and are linked to a restaurant.&lt;/p&gt;

&lt;h3&gt;
  
  
  Display dishes
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fu4hzy41jvhczwkmi5bte.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fu4hzy41jvhczwkmi5bte.gif" alt="Dishes list"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will use a new route for &lt;code&gt;/restaurants&lt;/code&gt; that will take in the ID of restaurant and return the list of dishes for that restaurant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd ..
cd pages
touch restaurants.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Path: &lt;code&gt;/frontend/pages/restaurants.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Now you should see your list of dishes associated with that restaurant if you navigate via the  browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We will add the cart in the upcoming sections, hang tight!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You will notice that if you navigate to the restaurant route and hit refresh, you will get a 404 page. This is because when you click the Link component the client is handling the routing, but on refresh the route is not found by the server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Faxngddmx4qbetowge8it.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Faxngddmx4qbetowge8it.png" alt="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To handle this we can setup an express server coupled with Next to render the route properly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next create a file &lt;code&gt;server.js&lt;/code&gt; inside the root of your project directory.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
touch server.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Path: &lt;code&gt;/frontend/server.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;To use the custom express server edit your &lt;code&gt;packages.json&lt;/code&gt; file and replace the script section with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node server.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;NODE_ENV=production node server.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Restart the dev server,&lt;/strong&gt;&lt;br&gt;
now with a refresh you should see the appropriate dishes as expected on a page refresh.&lt;/p&gt;

&lt;p&gt;🔐 In the next section, you will learn how to &lt;strong&gt;authenticate users in your app&lt;/strong&gt; (register, logout &amp;amp; login): &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho"&gt;https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
      <category>strapi</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🍝 Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe - 🏠 Restaurants list (part 2/7)</title>
      <dc:creator>Ryan </dc:creator>
      <pubDate>Mon, 04 Feb 2019 02:44:56 +0000</pubDate>
      <link>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce</link>
      <guid>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0294g6s34sm0586ozarz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0294g6s34sm0586ozarz.png" alt="Strapi Next.js tutorial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This tutorial is part of the « Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe » tutorial series.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of contents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏗️ &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----setup-part-17-ked"&gt;Setup&lt;/a&gt; (part 1) &lt;/li&gt;
&lt;li&gt;🏠 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce"&gt;Restaurants&lt;/a&gt; (part 2) &lt;strong&gt;-current&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🍔 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh/"&gt;Dishes&lt;/a&gt; (part 3)&lt;/li&gt;
&lt;li&gt;🔐 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho"&gt;Authentication&lt;/a&gt; (part 4)&lt;/li&gt;
&lt;li&gt;🛒 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e"&gt;Shopping Cart&lt;/a&gt; (part 5)&lt;/li&gt;
&lt;li&gt;💵 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph"&gt;Order and Checkout&lt;/a&gt; (part 6)&lt;/li&gt;
&lt;li&gt;🚀 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e"&gt;Bonus: Deploy&lt;/a&gt; (part 7) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note: the **source code&lt;/em&gt;* is &lt;strong&gt;available on GitHub&lt;/strong&gt;: &lt;a href="https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*" rel="noopener noreferrer"&gt;https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  🏠 Restaurants list
&lt;/h2&gt;

&lt;p&gt;First of all, we need to display the list of restaurants in our web app. Of course, this list is going to be managed through our API. So, we are going to start configuring it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Define Content Type
&lt;/h3&gt;

&lt;p&gt;A Content Type, also called a &lt;code&gt;model&lt;/code&gt;, is a type of data. A Strapi API includes, by default, the &lt;code&gt;user&lt;/code&gt; Content Type. Right now, we need restaurants, so our new Content Type is going to be, as you already guessed, &lt;code&gt;restaurant&lt;/code&gt; (Content Types are always singular).&lt;/p&gt;

&lt;p&gt;Here are the required steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the Content Type Builder (&lt;a href="http://localhost:1337/admin/plugins/content-type-builder" rel="noopener noreferrer"&gt;http://localhost:1337/admin/plugins/content-type-builder&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Add Content Type&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;restaurant&lt;/code&gt; as name.&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Add New Field&lt;/code&gt; and create the followings fields:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;name&lt;/code&gt; with type String.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;description&lt;/code&gt; with type Text with Rich Text Editor (in the Advanced Settings section of the modal, select &lt;code&gt;Display as a WYSIWYG&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;image&lt;/code&gt; with type &lt;code&gt;Media&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Click on Save.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3fpbccr35t7l79ow2jm5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3fpbccr35t7l79ow2jm5.gif" alt="Content Type Builder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, your server should have automatically restarted and a new link &lt;code&gt;Restaurant&lt;/code&gt; appears in the left menu.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add some entries
&lt;/h3&gt;

&lt;p&gt;Well done! You created your first Content Type. The next step is to add some restaurants in your database. To do so, click on "Restaurant" in the left menu (&lt;a href="http://localhost:1337/admin/plugins/content-manager/restaurant" rel="noopener noreferrer"&gt;http://localhost:1337/admin/plugins/content-manager/restaurant&lt;/a&gt;). &lt;/p&gt;

&lt;p&gt;You are now in the Content Manager plugin: an auto-generated user interface which let you see and edit entries.&lt;/p&gt;

&lt;p&gt;Let's create a restaurant:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on &lt;code&gt;Add New Restaurant&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Give it a name, a description and drop an image.&lt;/li&gt;
&lt;li&gt;Save it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Create as many restaurants as you would like to see in your apps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1q8r1wo25xhgc5h9z7xx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1q8r1wo25xhgc5h9z7xx.gif" alt="Content Manager"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Allow access
&lt;/h3&gt;

&lt;p&gt;Having the items in database is great. Being able to request them from an API is even better. As you already know, Strapi's mission is to create API (I have got a super secret anecdote for you: its name is coming from Boot*&lt;em&gt;strap&lt;/em&gt;* your &lt;strong&gt;API&lt;/strong&gt; 😮).&lt;/p&gt;

&lt;p&gt;When you were creating your &lt;code&gt;restaurant&lt;/code&gt; Content Type, Strapi created, behind the scene, a few set of files located in &lt;code&gt;api/restaurant&lt;/code&gt;. These files include the logic to expose a fully customisable CRUD API. The &lt;code&gt;find&lt;/code&gt; route is available at &lt;a href="http://localhost:1337/restaurants" rel="noopener noreferrer"&gt;http://localhost:1337/restaurants&lt;/a&gt;. Try to visit this URL and you will be surprised to be blocked by a 403 forbidden error. This is actually totally normal: Strapi APIs are secured by design.&lt;/p&gt;

&lt;p&gt;Don't worry, making this route accessible is actually super intuitive:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the &lt;code&gt;Roles &amp;amp; Permissions&lt;/code&gt; section of the admin plugin (&lt;a href="http://localhost:1337/admin/plugins/users-permissions" rel="noopener noreferrer"&gt;http://localhost:1337/admin/plugins/users-permissions&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Public&lt;/code&gt; role.&lt;/li&gt;
&lt;li&gt;Tick the &lt;code&gt;find&lt;/code&gt; and &lt;code&gt;findone&lt;/code&gt; checkboxes of the &lt;code&gt;Restaurant&lt;/code&gt; section.&lt;/li&gt;
&lt;li&gt;Save.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Important&lt;/em&gt;: do the same thing for the &lt;code&gt;authenticated&lt;/code&gt; role.&lt;/p&gt;

&lt;p&gt;Now go back to &lt;a href="http://localhost:1337/restaurants:" rel="noopener noreferrer"&gt;http://localhost:1337/restaurants:&lt;/a&gt; at this point, you should be able to see your list of restaurants.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkhqfzezl5gxqk8op1qf0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkhqfzezl5gxqk8op1qf0.gif" alt="Users Permissions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Enabling GraphQL
&lt;/h3&gt;

&lt;p&gt;By default, API generated with Strapi are best on REST conventions. What if I would tell you that you could transform them into GraphQL within 10 seconds?&lt;/p&gt;

&lt;p&gt;Well, let me prove you that.&lt;/p&gt;

&lt;p&gt;A GraphQL plugin, which will make all the work for you, is available for Strapi. Install it with the Strapi CLI:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;navigate to your backend folder where strapi is installed and install graphql using the strapi install command:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd backend
strapi install graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Or click "Marketplace" on your admin dashboard and select GraphQL&lt;/p&gt;

&lt;p&gt;And that's it, you are done installing GraphQL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Make sure to restart your strapi server if it does not auto restart&lt;/strong&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Important:
&lt;/h1&gt;
&lt;h4&gt;
  
  
  Downgrage graphql-js dependency
&lt;/h4&gt;

&lt;p&gt;With the current implementation you will receive a GraphQL error when trying to query a MongoDB _id field:&lt;/p&gt;

&lt;p&gt;This is currently being fixed by the graphql-js maintainers but as of time of writing has not been fixed (github issue linked below).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;message: "ID cannot represent value: { _bsontype: "ObjectID", id:  }"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fty52s68zx1t3tvuhcdv5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fty52s68zx1t3tvuhcdv5.png" alt="picture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is caused by a breaking change in the graphql-js update on how the ID's from a MongoDB are serialized: &lt;a href="https://github.com/graphql/graphql-js/issues/1518" rel="noopener noreferrer"&gt;https://github.com/graphql/graphql-js/issues/1518&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Based on the comments it looks like the maintainers are working on a fix but as of the time of writing (10/12/2018) the fix is to downgrade your graphql package to: GraphQL 0.13.2.&lt;/p&gt;

&lt;p&gt;The dependency package is in the &lt;strong&gt;/backend&lt;/strong&gt; folder under the GraphQL plugin folder listed at: &lt;code&gt;/backend/plugins/graphql/&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd plugins/graphql
npm install graphql@0.13.2 --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Inside of your packages.json file your graphql dependency should be listed as &lt;code&gt;"graphql": "0.13.2"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Until the issue is fixed if you upgrade your packages inside the server you will break the implementation.&lt;/strong&gt;&lt;/p&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0363m11lbi58h2kzsdsf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0363m11lbi58h2kzsdsf.png" alt="GraphQL installation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Restart your server, go to &lt;a href="http://localhost:1337/graphql" rel="noopener noreferrer"&gt;http://localhost:1337/graphql&lt;/a&gt; and try this query:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;restaurants&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;_id&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwu5i7udgq5zhad13e356.gif" alt="Strapi GraphQL"&gt;
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Display restaurants
&lt;/h3&gt;

&lt;p&gt;It looks you are going to the right direction. What if we would display these restaurants in our Next app?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzrjowwba57275b9xmkwz.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzrjowwba57275b9xmkwz.gif" alt="Restaurants list"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Install Apollo in the &lt;strong&gt;frontend of our application&lt;/strong&gt;, navigate to the &lt;code&gt;/frontend&lt;/code&gt; folder:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd ..
cd ..
cd frontend
yarn add react-apollo next-apollo graphql gql recompose

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;To connect our application with GraphQL we will use Apollo and the next-apollo implementation to wrap our components in a withData HOC to give them access to make apollo data queries.&lt;/p&gt;

&lt;p&gt;There are a couple differnt approaches to implementing GraphQL into a Nextjs app, the approach we will take is extracting the Apollo logic into lib file and wrapping our components with a Higher Order Component called withData to handle the GQL queries inside each respective components.&lt;/p&gt;

&lt;p&gt;Example repo detailing the Apollo Next.js implementation:&lt;br&gt;
&lt;a href="https://github.com/adamsoffer/next-apollo-example" rel="noopener noreferrer"&gt;https://github.com/adamsoffer/next-apollo-example&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Create a lib directory in the root of the project:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir lib
cd lib
touch apollo.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;Path: &lt;code&gt;/frontend/lib/apollo.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;We will generate the list of Restaurants inside a RestaurantList file as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd components

mkdir RestaurantList
cd RestaurantList
touch index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Path: &lt;code&gt;/frontend/components/RestaurantList/index.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Now update your &lt;code&gt;/pages/index.js&lt;/code&gt; home route to display the Restaurant list:&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/pages/index.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We will need to update our &lt;code&gt;_app.js&lt;/code&gt; file to wrap our application with the Apollo Provider that will enable GraphQL to make queries:&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/pages/_app.js&lt;/code&gt;&lt;br&gt;
 &lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Now you should see the list of restaurants on the page.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well done!&lt;/p&gt;

&lt;p&gt;🍔 In the next section, you will learn how to display the &lt;strong&gt;list of dishes&lt;/strong&gt;: &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh/"&gt;https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
      <category>strapi</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🍝 Cooking a Deliveroo clone with Next.js (React), GraphQL, Strapi and Stripe - 🏗️ Setup (part 1/7)</title>
      <dc:creator>Ryan </dc:creator>
      <pubDate>Mon, 04 Feb 2019 02:43:43 +0000</pubDate>
      <link>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----setup-part-17-ked</link>
      <guid>https://dev.to/ryanaz/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----setup-part-17-ked</guid>
      <description>&lt;p&gt;This tutorial will be adapted to use &lt;strong&gt;Next.js&lt;/strong&gt; (React) over Nuxt (Vue) on the front end, complete with &lt;strong&gt;GraphQL, Stripe, Strapi and React Context&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Get ready to develop a &lt;strong&gt;Deliveroo clone, using amazing technologies: &lt;a href="https://nextjs.org" rel="noopener noreferrer"&gt;Next.js&lt;/a&gt; (&lt;a href="https://reactjs.org" rel="noopener noreferrer"&gt;React&lt;/a&gt;), &lt;a href="https://graphql.org" rel="noopener noreferrer"&gt;GraphQL&lt;/a&gt;, &lt;a href="http://stripe.com/" rel="noopener noreferrer"&gt;Stripe&lt;/a&gt; and &lt;a href="https://strapi.io/" rel="noopener noreferrer"&gt;Strapi&lt;/a&gt;&lt;/strong&gt;! From signup to order, you are going to let users discover restaurants, dishes and select their happy meal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd0llou78vh8qc9jzynpd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd0llou78vh8qc9jzynpd.png" alt="Strapi Next.js tutorial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;demo of the final result&lt;/strong&gt; should make you hungry:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftbmklb7jcsr2766gba0p.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftbmklb7jcsr2766gba0p.gif" alt="Final Walk Through 3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: the **source code&lt;/em&gt;* is &lt;strong&gt;available on GitHub&lt;/strong&gt;: &lt;a href="https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*" rel="noopener noreferrer"&gt;https://github.com/strapi/strapi-examples/tree/master/nextjs-react-strapi-deliveroo-clone-tutorial*&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Screenshots of final product:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgtjlxaou10zxlw8ym9t8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgtjlxaou10zxlw8ym9t8.png" alt="first"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhduqy4dqy6zg4w0ause7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhduqy4dqy6zg4w0ause7.png" alt="second"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6v35vzh4kf97um3z266u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6v35vzh4kf97um3z266u.png" alt="third"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Strapi:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/strapi/strapi" rel="noopener noreferrer"&gt;&lt;strong&gt;Strapi&lt;/strong&gt; &lt;/a&gt; is the most advanced open-source &lt;strong&gt;Node.js Headless Content Management System&lt;/strong&gt; used to build scalable, secure, production ready API's quickly and efficiently saving developers countless hours of development.&lt;/p&gt;

&lt;p&gt;With its extensible plugin system, it provides a large set of built-in features: Admin Panel, Authentication &amp;amp; Permissions management, Content Management, API Generator, etc. Unlike online CMS, &lt;strong&gt;Strapi is 100% open-source&lt;/strong&gt; (take a look at the &lt;a href="https://github.com/strapi/strapi" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;), which means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strapi is &lt;strong&gt;completely free&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You can &lt;strong&gt;host it on your own servers&lt;/strong&gt;, so you own the data.&lt;/li&gt;
&lt;li&gt;It is entirely &lt;strong&gt;customizable and extensible&lt;/strong&gt;, thanks to the plugin system.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Next.js:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/zeit/next.js/" rel="noopener noreferrer"&gt; &lt;strong&gt;Next&lt;/strong&gt; &lt;/a&gt; is a lightweight development framework to create static, server rendered applications in &lt;strong&gt;React&lt;/strong&gt;. Next.js will take care of the heavy lifting of the application such as &lt;em&gt;code splitting, HMR (hot module replacement) and SSR (server side rendering)&lt;/em&gt; and allow us to focus on the application.&lt;/p&gt;
&lt;h3&gt;
  
  
  React:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/facebook/react" rel="noopener noreferrer"&gt;&lt;strong&gt;React&lt;/strong&gt;&lt;/a&gt; is one of the most popular front end Javascript frameworks, developed by facebook and used by countless tech companies including &lt;em&gt;Netflix, Airbnb and Github&lt;/em&gt; to build applications. React is a declarative library that makes it easy to create interactive user interfaces, keeping the code base organized through its &lt;em&gt;component based architecture&lt;/em&gt;.  &lt;/p&gt;
&lt;h3&gt;
  
  
  GraphQL:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/graphql" rel="noopener noreferrer"&gt;&lt;strong&gt;GraphQL&lt;/strong&gt;&lt;/a&gt; is a query language also developed by Facebook to allow the front end of an application to easily query an application's API. Each query requests only the data needed to be rendered by the current view. This allows the developer to craft a great user experience across &lt;em&gt;multiple devices and screen sizes&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Stripe:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/stripe" rel="noopener noreferrer"&gt;&lt;strong&gt;Stripe&lt;/strong&gt;&lt;/a&gt; is one of (if not the largest) payment processor's for application today. Stripe has developed the tools and SDKs to allow developers to craft and integrate &lt;em&gt;secure, compliant payment processing&lt;/em&gt; into any app with easy.&lt;/p&gt;
&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🏗️ &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----setup-part-17-ked"&gt;Setup&lt;/a&gt; (part 1) &lt;strong&gt;-current&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🏠 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce"&gt;Restaurants&lt;/a&gt; (part 2)&lt;/li&gt;
&lt;li&gt;🍔 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----dishes-list-part-37-5eh/"&gt;Dishes&lt;/a&gt; (part 3)&lt;/li&gt;
&lt;li&gt;🔐 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----authentication-part-47-eho"&gt;Authentication&lt;/a&gt; (part 4)&lt;/li&gt;
&lt;li&gt;🛒 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----shopping-cart-part-57-2h1e"&gt;Shopping Cart&lt;/a&gt; (part 5)&lt;/li&gt;
&lt;li&gt;💵 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----order-and-checkout-part-67-fph"&gt;Order and Checkout&lt;/a&gt; (part 6)&lt;/li&gt;
&lt;li&gt;🚀 &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----bonus-deploy---part-77-1i8e"&gt;Bonus: Deploy&lt;/a&gt; (part 7) 
## 🏗️ Setup&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Next
&lt;/h3&gt;

&lt;p&gt;To setup Next.js we will need an empty directory to install the library and host our project root.&lt;/p&gt;

&lt;p&gt;We will split our project into two parts, one for the front end (Next.js code) and one for the backend (Strapi code).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;strapi-deliveroo
&lt;span class="nb"&gt;cd &lt;/span&gt;strapi-deliveroo
&lt;span class="nb"&gt;mkdir &lt;/span&gt;frontend
&lt;span class="nb"&gt;cd &lt;/span&gt;frontend

yarn add next react react-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;Note: I am using yarn as my package manager, you can also use npm and execute &lt;code&gt;npm install --save next react react-dom&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Add the following to your &lt;code&gt;package.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So that your file looks like this (your package dependencies may have different versions depending on the time of install):&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dependencies&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^7.0.2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^16.6.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^16.6.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next.js uses any JavaScript file in the &lt;code&gt;/pages&lt;/code&gt; directory as the routes for the application. To setup simply create the &lt;code&gt;/pages&lt;/code&gt; directory and add an &lt;code&gt;index.js&lt;/code&gt; file with:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir pages
cd pages
touch index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now that we have our main route (index.js), this will be loaded each time the browser URL is at the root (i.e. &lt;a href="http://www.yourapp.com" rel="noopener noreferrer"&gt;www.yourapp.com&lt;/a&gt;). To test this you can insert the following into the index.js file:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Welcome&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;To view the application running, start the local dev server using:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Your application should now be visible at &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Be sure to create a &lt;code&gt;.gitignore&lt;/code&gt; in the project root and add &lt;code&gt;.next&lt;/code&gt; and &lt;code&gt;node_modules&lt;/code&gt; directories to it:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
touch .gitignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* .gitignore */
node_modules
.next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Adding Bootstrap&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For this tutorial, we will use &lt;a href="https://reactstrap.github.io/" rel="noopener noreferrer"&gt;react-strap&lt;/a&gt; to implement Bootstrap 4 into our application. For the CSS styling we will import directly from a CDN.&lt;/p&gt;

&lt;p&gt;First install Reactstrap:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add reactstrap bootstrap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;reactstrap&lt;/strong&gt; is simply a front end library to easily create Bootstrap components and styling.&lt;/p&gt;

&lt;p&gt;To import the CSS and share a Layout component across all our pages we will use a custom &lt;code&gt;_app.js&lt;/code&gt; file inside the &lt;strong&gt;pages directory&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This file will serve to override the default App.js used by Next and be rendered on each page, allowing us to set global styles/shared components in one place.&lt;/p&gt;

&lt;p&gt;You can read more about the &lt;code&gt;_app.js&lt;/code&gt; handling here: &lt;a href="https://nextjs.org/docs/#custom-app" rel="noopener noreferrer"&gt;https://nextjs.org/docs/#custom-app&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This will allow us the ability to import a &lt;code&gt;&amp;lt;Head&amp;gt;&lt;/code&gt; component and globally set the stylesheet inside the header.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd pages
touch _app.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Path: &lt;code&gt;/frontend/pages/_app.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Now if we add in some reactstrap components inside of &lt;code&gt;index.js&lt;/code&gt; we should see the bootstrap styling applied once we restart our server.&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/pages/index.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Restart your server to apply the new changes.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl585ewkp9fikh7scnm46.png" alt="picture"&gt;
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Designing the page
&lt;/h4&gt;

&lt;p&gt;Now that we have Bootstrap running inside of our Next.js project, we can begin to style the basic shared front end components like the navbar.&lt;/p&gt;

&lt;p&gt;First create a folder to store our components and create our layout component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
mkdir components
cd components
touch Layout.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Nextjs uses the &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; component to perform the client side routing between pages. The Link component is just a Higher Order Component and can accept any html tag that can handle an onClick handler (&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;,&lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt;,&lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; etc.).&lt;/p&gt;

&lt;p&gt;This will cause us to have to make a few modifications outside of the reactstrap documentation. To style our navbar we can use  the built in CSS in JS &lt;code&gt;&amp;lt;style jsx&amp;gt;&lt;/code&gt; shipped by default with nextjs.&lt;/p&gt;

&lt;p&gt;Inserting CSS in JS as:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="nx"&gt;jsx&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`
  a { color: yellow }
`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/style&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Allows us to scope CSS to the components the style tag is rendered in, you can also pass in the global option to set a global style: &lt;code&gt;&amp;lt;style jsx global&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can read more on CSS in JS in the Next documents &lt;a href="https://nextjs.org/docs/#css-in-js" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Open the &lt;code&gt;Layout.js&lt;/code&gt; file and create the shared layout components and insert the Stripe script (for later) as follows:&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/components/Layout.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Edit the &lt;code&gt;index.js&lt;/code&gt; file to use the new Layout component:&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/pages/index.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;You should now have a shared header bar across all your pages:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1gencefjkukmrf0kre60.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1gencefjkukmrf0kre60.png" alt="Bootstrap"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will create two additional pages to allow users to sign in and sign up at &lt;code&gt;/signin&lt;/code&gt; and &lt;code&gt;/signup&lt;/code&gt; respectively. &lt;/p&gt;

&lt;p&gt;You will need to create the corresponding files inside the &lt;code&gt;/pages&lt;/code&gt; directory for next to recognize the routes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd pages

touch signin.js
touch signup.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Populate the files with the following code that we will come back to once our Strapi server is setup.&lt;/p&gt;

&lt;p&gt;Path: &lt;code&gt;/frontend/pages/signup.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Path: &lt;code&gt;/frontend/pages/signin.js&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;p&gt;You should now see the routes at &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Strapi
&lt;/h3&gt;

&lt;p&gt;Having a frontend is good, but your app obviously needs a backend to manage users, restaurants, dishes and orders. To make the magic happen, let's create a Strapi API.&lt;/p&gt;

&lt;h4&gt;
  
  
  Install Strapi
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Requirements: please make sure to use &lt;a href="https://nodejs.org/en/download" rel="noopener noreferrer"&gt;Node 9&lt;/a&gt; (or more) and have either &lt;a href="https://docs.mongodb.com/manual/installation/" rel="noopener noreferrer"&gt;MongoDB&lt;/a&gt;, Postgres or MySQL installed and running on your machine.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Install Strapi using npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i strapi@alpha -g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: Strapi v3 is still an alpha version, but it will be fine for this tutorial.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Generate a Strapi project
&lt;/h4&gt;

&lt;p&gt;Scaffold your API inside the &lt;code&gt;strapi-deliveroo&lt;/code&gt; through a single command line:&lt;/p&gt;

&lt;p&gt;Install a strapi server in a directory called &lt;code&gt;backend&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
cd ..
strapi new backend
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CLI will ask you to choose your database: select MongoDB, Postgres or MySQL. Then, fill the database information in (if you choose a DB other than mongo you will need to alter the _id field to id in the preceding GraphQL queries). The default values should work if you correctly installed the database system on your machine.&lt;/p&gt;

&lt;p&gt;Note: This tutorial uses MongoDB, once you create the strapi project you will be asked to start the Mongo instance before you can start your strapi server.&lt;/p&gt;

&lt;p&gt;Navigate to the installation of your MongoDB (default on MacOS)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~./data/db
mongod 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start you MongoDB server on your local machine and you can now start your Strapi Server.&lt;/p&gt;

&lt;h4&gt;
  
  
  Start the server
&lt;/h4&gt;

&lt;p&gt;Launch the Node.js server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd backend
strapi start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F49ebo3pzn35jah8gnrop.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F49ebo3pzn35jah8gnrop.png" alt="Strapi start"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Starting now, you should be able to visit the admin panel of your project: &lt;a href="http://localhost:1337/admin" rel="noopener noreferrer"&gt;http://localhost:1337/admin&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Create your first User
&lt;/h4&gt;

&lt;p&gt;Add your first user from the &lt;a href="http://localhost:1337/admin/plugins/users-permissions/auth/register" rel="noopener noreferrer"&gt;registration page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn9pei9osfx7e7cas23jp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn9pei9osfx7e7cas23jp.gif" alt="Strapi register"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Good job, you successfully setup both Next.js and Strapi projects! 🎉&lt;/p&gt;

&lt;p&gt;🏠 In the next section, you will learn how to display the &lt;strong&gt;list of restaurants&lt;/strong&gt;: &lt;a href="https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce"&gt;https://dev.to/ryanrez/-cooking-a-deliveroo-clone-with-nextjs-react-graphql-strapi-and-stripe----restaurants-list-part-27-10ce&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Protect your environment variables at all cost</title>
      <dc:creator>Ryan </dc:creator>
      <pubDate>Wed, 30 Jan 2019 02:03:22 +0000</pubDate>
      <link>https://dev.to/ryanaz/protect-your-environment-variables-at-all-cost-1if9</link>
      <guid>https://dev.to/ryanaz/protect-your-environment-variables-at-all-cost-1if9</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--liTSnzdh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9s005jlm2yjaesznhz1a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--liTSnzdh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9s005jlm2yjaesznhz1a.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the problem being solved?&lt;/strong&gt;&lt;br&gt;
The problem being solved is the accidental exposure of API keys, passwords or other sensitive data being exposed accidentally in a git repo&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Who is this for?&lt;/strong&gt; &lt;br&gt;
Beginners working with Git/Node.&lt;/p&gt;

&lt;p&gt;Speaking with a fellow dev recently, it was mentioned how he was updating an old github project and had accidentally pushed his AWS keys to github after adding the credentials.yml file to the project level .gitignore &lt;strong&gt;(hint, your git cache needs to be cleared if you add a file to the .gitignore file of an already tracked repo)&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Within 4 hours a notification email from Amazon had came that his account had been comprised, accompanied by the appropriate mitigation steps (change password, 2FA, check unauthorized instances and shut them down manually).&lt;/p&gt;

&lt;p&gt;Looking through his AWS account the next morning he found 20 EC2 instances had been started in every single region, US, EU, South Korea you name it. Data transfer usage billed in less than 24 hours sat at ~$10,000 with a projected monthly usage much much higher.&lt;/p&gt;

&lt;p&gt;A quick search on Google resulted in several Quora answers with similar results of being comprised and that Amazon was crediting back for the unauthorized usage, some with data transfer bills as high as $250,000. &lt;/p&gt;

&lt;p&gt;This is what inspired this article on the best practices to protect one of the most important aspects of a project, your environment variables. &lt;strong&gt;My hope is that you will implement these strategies and protect yourself or your employer from a security breach.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Environment Variables
&lt;/h2&gt;

&lt;p&gt;API keys should avoid being hard coded in code at all costs as these values could easily be uploaded to a shared git repository by accident, giving unvetted access to your account with the API provider. &lt;/p&gt;

&lt;p&gt;Environment variables can be managed in a separate .env/credentials file locally in the project, stored in your system variables on your machine and secured in production on the server as an environment variable. &lt;/p&gt;

&lt;p&gt;This allows the credential file to be added to a local .gitignore or a global .gitignore to prevent accidental upload.&lt;/p&gt;

&lt;p&gt;The following steps are what I recommend to help secure you and your teams credentials.&lt;/p&gt;
&lt;h2&gt;
  
  
  Global .gitignore
&lt;/h2&gt;

&lt;p&gt;Project .gitignore files are well known, but the lesser known more important .gitignore file can be setup on your machine and apply to every git repository you track.&lt;/p&gt;

&lt;p&gt;To setup, open the terminal and type:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$ git config --global core.excludesfile ~/.gitignore_global&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now you can add any files or extensions you want to make sure don't make it to a git repository.&lt;/p&gt;

&lt;p&gt;You can open the file from the command line with:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$ vim ~/.gitignore_global&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once inside vim editor hit &lt;code&gt;i&lt;/code&gt; to insert text and &lt;code&gt;:q&lt;/code&gt; to save/exit when finished&lt;/p&gt;

&lt;p&gt;Some common entries that would be used for credentials include &lt;code&gt;.env variables.env credentials.yml /node_modules&lt;/code&gt; depending on your project/coding language.&lt;/p&gt;

&lt;p&gt;An extensive list of recommend file extensions can be found here:&lt;br&gt;
&lt;a href="https://gist.github.com/octocat/9257657"&gt;https://gist.github.com/octocat/9257657&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Local project .gitignore
&lt;/h2&gt;

&lt;p&gt;This is the most common type of .gitignore and can be found in the git project root directory.&lt;/p&gt;

&lt;p&gt;This file is simply created after running &lt;code&gt;git init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Any file extensions, files or folders listed in this file will be ignored from git tracking.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/docs/gitignore"&gt;https://git-scm.com/docs/gitignore&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Clearing the git cache
&lt;/h2&gt;

&lt;p&gt;If you have already initialized your git repo and want to add files to your .gitignore after having already tracked files you will need to clear the git cache using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git rm -r --cached .
$ git add .`
$ git commit -m "new files added to .gitignore not being tracked"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you forget to clear the cache and add a file you don't want tracked to the gitignore and do a normal &lt;code&gt;git add .&lt;/code&gt; &lt;code&gt;git commit -m "file will be added to git"&lt;/code&gt; your file will be pushed to git unless you have setup the global .gitignore with the proper extension.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clearing Your Mistakes With BFG
&lt;/h2&gt;

&lt;p&gt;If you do happen to expose an API key by mistake, all hope is not lost. Make sure to cancel and rotate the key so no damage can be done. You can also remove text/folders from a git repo easily using BFG&lt;/p&gt;

&lt;p&gt;&lt;a href="https://rtyley.github.io/bfg-repo-cleaner/"&gt;https://rtyley.github.io/bfg-repo-cleaner/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Install on Mac:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install bfg
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Now you can remove text from your git commit history using:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ bfg --replace-text variables_file.env
$ git add .
$ git commit -m 'text removed'
$ git push --force
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will insert &lt;em&gt;REMOVED&lt;/em&gt; for text of this file like so:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--liTSnzdh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9s005jlm2yjaesznhz1a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--liTSnzdh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9s005jlm2yjaesznhz1a.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please read the instructions printed for BFG as this won't delete the file you will have to do that manually, this will only remove the text from your commit history.&lt;/p&gt;

&lt;p&gt;You can also remove the entire file/folder&lt;br&gt;
&lt;strong&gt;&lt;code&gt;$ bfg --delete-folders .git --delete-files .git  --no-blob-protection  my-repo.git&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Dotenv (.env)
&lt;/h2&gt;

&lt;p&gt;All this talk on how to protect your API keys, but how do actually prevent hard coding your keys?&lt;/p&gt;

&lt;p&gt;Simple, using an NPM package called &lt;strong&gt;dotenv&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Install with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# with npm 
$ npm install dotenv

# or with Yarn 
$ yarn add dotenv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Now in your application, typically at the top of the server.js file use:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$ require('dotenv').config()&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Create a &lt;code&gt;.env&lt;/code&gt; file in the root of your project structured as:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API_KEY=3nds234nds2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you have access to the key using &lt;strong&gt;&lt;code&gt;process.env.API_KEY&lt;/code&gt;&lt;/strong&gt; which will be converted to your key value when your code is built. Any commit to git will see &lt;strong&gt;&lt;code&gt;proccess.env.API_KEY&lt;/code&gt;&lt;/strong&gt; rather than your actual key value.&lt;/p&gt;

&lt;p&gt;Now you can sleep at night knowing your keys are protected!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>setup</category>
      <category>environment</category>
    </item>
  </channel>
</rss>
