<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Adewale Toluwani on Medium]]></title>
        <description><![CDATA[Stories by Adewale Toluwani on Medium]]></description>
        <link>https://medium.com/@badasukerubin?source=rss-6f9475ff8c67------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RRnQxSU2_IaUOVjuosa9xg.jpeg</url>
            <title>Stories by Adewale Toluwani on Medium</title>
            <link>https://medium.com/@badasukerubin?source=rss-6f9475ff8c67------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 22:42:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@badasukerubin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The simple and awesome way to deploy a Laravel and React.js]]></title>
            <link>https://medium.com/@badasukerubin/the-simple-and-awesome-way-to-deploy-a-laravel-and-react-js-a8b547cbbc75?source=rss-6f9475ff8c67------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8b547cbbc75</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[shared-hosting]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Adewale Toluwani]]></dc:creator>
            <pubDate>Wed, 13 Nov 2019 17:47:08 GMT</pubDate>
            <atom:updated>2019-11-13T17:47:08.692Z</atom:updated>
            <content:encoded><![CDATA[<h3>The simple and awesome way to deploy a Laravel and React.js application on a shared hosting server using git</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ksF7jS47OSPBChQ-m-4M-Q.gif" /><figcaption>Some gopher looking guy sitting on seemingly dangerous waves while sending tomato planes from his PC to fast spinning monitors 😂</figcaption></figure><p>I can quite imagine various reasons why you chose to use a shared hosting server for your Laravel + React application, cost — I guess being a key factor, you should know however that Taylor did not <em>really </em>design Laravel with shared hosting servers in perspective. This has often resulted in vulnerabilities whereby sensitive configuration data are can be easily spoofed by attackers.<br>Although this article will help you fully understand how to deploy (almost CI/CD 😉) and manage your application on a shared hosting server, you can always opt for <a href="https://forge.laravel.com/">Laravel Forge</a> or 🌟<a href="https://vapor.laravel.com/">Laravel Vapor</a>🌟 for more convenience, better security and scalability at quite cost-effective prices.</p><h4>Quick Peek (summary for in-a-hurry readers)</h4><ol><li><strong>The Usual 500s</strong>: We will update our PHP version and enable the fileinfo extension.</li><li><strong>The Secure Shell</strong>: We will generate SSH keys and log into cPanel from our local terminal.</li><li><strong>The Push-Pull Effect</strong>: We will push local files to github and fetch them to our shared hosting server using the SSH.</li><li><strong>The Few Tips</strong>: Just a crumb of information available only at the end of the article 😋.</li></ol><h4><strong>The Usual 500s</strong></h4><p>This stage kind of determines whether you will be able to deploy your Laravel application or fallback to an older version (not recommended). Except you are deploying a version less than 5.5, you are required to have PHP &gt;= 7.0.0. I have come across shared hosting service providers in the <em>past </em>that do not follow the latest trends— you are often stuck with older PHP versions or you can not select extensions (a disadvantage). If the PHP version in your hosting server does not align or surpass Laravel’s requested version, this will result to an internal server error — error 500. <br>To upgrade PHP: Scroll to <strong>SOFTWARE tab</strong> &gt;&gt; Select <em>PHP Version</em><strong><em> &gt;&gt; </em>Select the version that works with your application and check on fileinfo.<br></strong>If you were not successful performing the actions above, try contacting your hosting provider for an upgrade.</p><h4>The Secure Shell</h4><p>I believe so much in CLI computing, hence sadly or not we will not be using much of the GUI; I feel this makes our deployment process way faster and more efficient. We will make use of the secure shell (SSH) to login to our hosting server by following this simple processes:</p><ul><li>Login to cPanel on your browser &gt;&gt; Scroll to <strong>SECURITY tab </strong>&gt;&gt; Select <em>SSH Access</em> &gt;&gt; Select <em>Manage SSH Keys</em> &gt;&gt; Select <em>Generate a New Key</em> &gt;&gt; <strong>Leave all values in the form field to default, but make sure to paste the *<em>Key Password </em>in a safe place as it will be used to access your server from your local terminal (You can use the Password Generator)</strong> &gt;&gt; Select <em>Generate Key</em>.<br>The Public Key generated should be unauthorized by default (check under <strong>Authorization Status </strong>of the <strong>Public Keys tab</strong>) hence to authorize, select <em>Manage </em>&gt;&gt; Select <em>Authorize</em>.<br>Now select <em>Go Back</em> and download the <strong>Private Key </strong>by selecting <em>View/Download</em> (check under <strong>Actions </strong>of the <strong>Private Keys tab</strong>).</li><li>Now copy the downloaded <strong>Private Key</strong> <strong><em>id_rsa</em></strong> from your download folder into <em>C:\Users\YOURPC\.ssh</em> folder or short <em>~/.ssh</em> folder.<br>You can now SSH into your host by running the command ssh CurrentUser@SharedIP Address<strong><em> </em></strong>(The variables can be found on the dashboard of your cPanel where <strong><em>CurrentUser</em></strong> is your cPanel username and <strong><em>Shared IP Address </em></strong>is the assigned IP Address of your shared host. <br>Enter the yes to the warning and <strong>*<em>Key Password </em></strong>as the passphrase in the prompts that follow and you should be shown your way in 🙃.</li><li>We can only hope our two major players — composer and npm are already installed by your hosting provider; check by running composer -v and npm -v if not, run curl -sS <a href="https://getcomposer.org/installer">https://getcomposer.org/installer</a> | php — — install-dir=/usr/local/bin — filename=composer to install composer and curl <a href="https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh">https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh</a> | bash to install nvm (the node version manager) and then run nvm install node to install node and hence npm.</li></ul><h4>The Push-Pull Effect</h4><p>I would love to go through the process of pushing our project to github but to reduce the length of this post, I gladly refer you to <a href="https://scotch.io/tutorials/how-to-push-an-existing-project-to-github">this post about it</a>. <br>Now run this command to clone your project from github: git clone <a href="https://000kelvin@github.com/000kelvin/assit.git">https://username@github.com/</a><a href="https://000kelvin@github.com/000kelvin/assit.git">username</a><a href="https://000kelvin@github.com/000kelvin/assit.git">/project.git</a>, change directory into the project file and: Run composer install to install the required php packages and then run npm install to install the required javascript packages.</p><p>Run shopt -s dotglob to grab all files and directory including the dot files (.env and co) change directory into <em>public_html </em>and make sure there are no files present there (such as hosting files etc) — use ls to list directory contents, rm filename1, filename2 to remove file and rm -r foldername to remove a folder and its contents. <br>Change back to the project directory and run mv public/* ../public_html to move the contents of the public directory of your fetched project to the <em>public_html</em> that would be visible to the outside world — you can change directory back to <em>public_html </em>and list files to confirm that the files have moved successfully. <br>Now go back to the project directory and run php artisan key:generateto generate a new APP_KEY for your laravel application then run cp .env.example .env to copy a new environment file <strong><em>.env</em></strong> from <strong><em>.env.example </em></strong>file. The <strong><em>.env </em></strong>file is absent from your project directory due to the fact that git ignores and does not push your environment file amongst others for security reasons, this implies that you need to edit the new <strong><em>.env </em></strong>to match the one on your local machine — I prefer the nano editor, you can ofcourse check to see which editors are installed on your cPanel server for use; vim is also a great alternative.<br>Run nano .env to edit your environment file to suit your local environment configurations using nano, a nice guide is <a href="https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/">found here</a>.<br>Run the following consecutively to optimize your application, clear routes cache and configuration cache:</p><pre>composer dumpautoload -o</pre><pre>php artisan config:cache</pre><pre>php artisan route:cache</pre><p>We are now at the final stage, change directory back into <em>public_html </em>and run nano index.php in order to conform our application with our new path and avoid <strong>The Usual 500s</strong>; we will be editing composer’s <em>autoload.php </em>and Laravel-bootstrap’s <em>app.php</em> path as shown below:</p><pre>// This...<br>require __DIR__.&#39;/../vendor/autoload.php&#39;;<br>// ...is edited to this: <br>require __DIR__.&#39;/../project/vendor/autoload.php&#39;;</pre><pre>//...and...</pre><pre>// this...<br>$app = require_once __DIR__.&#39;/../bootstrap/app.php&#39;;<br>// ...is edited to this:<br>$app = require_once __DIR__.&#39;/../project/bootstrap/app.php&#39;;</pre><p>…where <em>project</em> is the name of your project folder in the root directory of your application. <br>Those are pretty much every important action you need to take to deploy your website to a shared hosting server in a simplified way.</p><h4>The Few Tips</h4><ol><li>Really, using shared hosting can be somewhat dangerous when you are dealing with websites that would utilize lots of resources and requires high-end security such as a large shopping website or one that stores credit card information etc.<br>I recommend that you try VPS, dedicated servers or just opt for <a href="https://forge.laravel.com/">Laravel Forge</a> or 🌟<a href="https://vapor.laravel.com/">Laravel Vapor</a>🌟.</li><li>Create git branches which you or other developers can work with confidently and add files and folders which could have varying contents with no distinct changes between local and production to <strong><em>.gitignore.</em></strong></li><li>Set up your database variables and add them to the <strong><em>.env </em></strong>file; edit APP_ENV to <em>production</em>, APP_DEBUGto <em>TRUE</em> and edit the APP_DEBUG to suit your project’s URL in the <strong><em>.env </em></strong>file.</li><li>The workflow is basically: <strong>make changes locally</strong> → <strong>push to github → pull to shared hosting server<br></strong>Pulling to shared hosting server can be automated by creating cron jobs or other tools for effeciency and ease.</li><li>Backup the application’s database at intervals.</li></ol><p><strong><em>Thank you very much for following till the very end, if you enjoyed this article in any way, clap for it. If you like me too, you can find me on </em></strong><a href="https://twitter.com/k_e_lv_i_n"><strong><em>twitter</em></strong></a><strong><em> — I actually don’t do much.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8b547cbbc75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Laravel and React.js the right way (Using user authentication).]]></title>
            <link>https://medium.com/@badasukerubin/setting-up-laravel-and-react-js-the-right-way-using-user-authentication-1cfadf3194e?source=rss-6f9475ff8c67------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cfadf3194e</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[single-page-applications]]></category>
            <dc:creator><![CDATA[Adewale Toluwani]]></dc:creator>
            <pubDate>Thu, 18 Jul 2019 17:19:34 GMT</pubDate>
            <atom:updated>2022-04-30T15:38:32.123Z</atom:updated>
            <content:encoded><![CDATA[<h3>Setting up Laravel and React.js the right way (Using user authentication)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c212PtnJILZsdRK7bcw6rQ.png" /><figcaption>Image from <a href="https://fullstackworld.com/">FullStackWorld</a></figcaption></figure><p>Upgraded Article: <a href="https://toluwaniadewale.com/blog/setting-up-laravel-and-reactjs-the-right-way-using-user-authentication">https://toluwaniadewale.com/blog/setting-up-laravel-and-reactjs-the-right-way-using-user-authentication</a></p><p>I was recently tasked by a client to create another ‘one of those application-like websites — the ones that don’t load 😂’; it’s actually called a SPA (Single Page Application). My forte being back-end development with PHP(Laravel), I knew I could use laravel’s buddy Vue.js which is totally perfect for the job; my problem with that was that I was already quite bored with Vue, so I decided to explore with React.js — <strong>NB</strong>:: It was my only project at the time and I had only picked up React about 2 weeks prior to the time.</p><p>By reading this article, I understand you already know what both are so there’s no need to lengthen this already <strong><em>long but very interesting article </em></strong>by doing the ‘My name is Peter Parker’ thingy. We will be creating home, 404, login, registration and dashboard page in this article.<br>We will be using: <br>1. PHP — Laravel (a framework); we will be using it’s REST API<br>2. Passport OAuth (a Laravel package for full OAuth2 server implementation)<br>3. JavaScript — React (a package)<br>4. MySQL database<br>5. Visual Studio Code; it used to be PhpStorm 😩 (I’ll write on the transition later)</p><h3>Back-end</h3><p>On second thought, please refer to <a href="https://medium.com/modulr/create-api-authentication-with-passport-of-laravel-5-6-1dc2d400a7f">https://medium.com/modulr/create-api-authentication-with-passport-of-laravel-5-6-1dc2d400a7f</a> on how to build an authentication system with Laravel API and Passport OAuth — Part 1 is actually enough for what we need.<br>We wouldn’t be needing much of Laravel’s routing as React comes with a quite awesome routing system, so add this in your <em>routes\web.php</em>,</p><pre>Route::view(&#39;/{path?}&#39;, &#39;index&#39;);</pre><p>The above code redirects all <em>first level url paths</em> in the browser to index view, this implies that paths like <em>localhost:8080/test</em> or <em>localhost:8080/error</em> will redirect us to the index view while higher orders like <em>localhost:8080/test/error</em> or <em>localhost:8080/test/error/sad</em> will return Laravel’s default 404 page — <strong>NB</strong>:: The above urls can also be routed to a controller to return views but then that wouldn’t be the point of a SPA 🤷‍ .<br>Next up, due to the fact that Vue wouldn’t be glad we’re making use of React instead; run the following in the terminal for your project very carefully 😄:</p><pre>php artisan preset react</pre><p>This actually replaces the default Vue scaffolding with React. If you check <em>resources/assets/js/components </em>folder, you should see an Example.js file (which we would rather refactor to Index.js instead) which is a react component.</p><p>Since it is the same server/domain that is used for both the front-end and back-end, we wouldn’t necessarily be needing <strong>Cross-origin resource sharing</strong> (<strong>CORS</strong>) or those sorts of things.</p><h3>Front-end</h3><p>We can now install all node modules — a galaxy of javascript packages and dependencies running the command:</p><pre>npm install</pre><p>Then to listen for file changes, we run the following in our terminal;</p><pre>npm run watch</pre><p>Next, we will remove everything within the &lt;body&gt;&lt;/body&gt; of our <em>resources\views\index.blade.php and replace with the following:</em></p><pre>&lt;div id=&quot;index&quot;&gt;&lt;/div&gt;</pre><pre>&lt;script src=&quot;{{ asset(&#39;js/app.js&#39;) }}&quot;&gt;&lt;/script&gt;</pre><p>This as you might already know renders our index view with react components. A somewhat important aspect of this setup I had to ponder on was setting up my views and component folders. My file structure placed in <em>resources\js</em> is presented below — you could always create or research a better one though;</p><pre>📂resources\js<br>  📂components<br>      // Takes in all the reusable components<br>      📂Footer<br>          Footer.js<br>      📂Header<br>          Header.js<br>      📂Home<br>          Home.js<br>  📂views<br>      📂NotFound<br>          NotFound.js<br>      📂Login<br>          Login.js<br>          LoginContainer.js<br>      📂Register<br>          Register.js<br>          RegisterContainer.js<br>      📂user<br>          📂Dashboard<br>              Dashboard.js<br>  app.js<br>  bootstrap.js<br>  Index.js<br>  PrivateRoute.js<br>  Router.js</pre><h4>app.js</h4><pre>require(&#39;./bootstrap&#39;);<br>require(&#39;./Index&#39;);</pre><p>Here we just reference the Index as the component to be used which we will create below</p><h4>Index.js</h4><pre>import React, {Component} from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br>import {BrowserRouter, Link, Route, Switch} from &#39;react-router-dom&#39;;<br>import Main from &#39;./Router&#39;;</pre><pre>class Index extends Component {<br>  render() {<br>    return (<br>      &lt;BrowserRouter&gt;<br>        &lt;Route component={Main} /&gt;<br>      &lt;/BrowserRouter&gt;<br>    );<br>  }<br>}<br>ReactDOM.render(&lt;Index/&gt;, document.getElementById(&#39;index&#39;));</pre><p>I expect you have a basic idea about routing in React so I’ll pass. If you don’t understand 🤔, which is totally not an evil thing and you want to; check out this article <a href="https://medium.com/the-andela-way/understanding-the-fundamentals-of-routing-in-react-b29f806b157e">https://medium.com/the-andela-way/understanding-the-fundamentals-of-routing-in-react-b29f806b157e</a>, if you don’t want to understand — that makes it totally evil 👿</p><h4>Bootstrap.js</h4><pre>window._ = require(&#39;lodash&#39;);</pre><pre>try {<br>  window.Popper = require(&#39;popper.js&#39;).default;<br>  window.$ = window.jQuery = require(&#39;jquery&#39;);<br>  <br>  require(&#39;bootstrap&#39;);<br>} catch (e) {}</pre><pre>// The axios part I might talk about<br>window.axios = require(&#39;axios&#39;);<br>window.axios.defaults.headers.common[&#39;X-Requested-With&#39;] = &#39;XMLHttpRequest&#39;;<br>let token = document.head.querySelector(&#39;meta[name=&quot;csrf-token&quot;]&#39;);</pre><pre>if (token) {<br>  window.axios.defaults.headers.common[&#39;X-CSRF-TOKEN&#39;] = token.content;<br>  } else {<br>  console.error(&#39;CSRF token not found: <a href="https://laravel.com/docs/csrf#csrf-x-csrf-token&#39;);">https://laravel.com/docs/csrf#csrf-x-csrf-token&#39;);</a><br>}</pre><p>Yeah, this or more…lol…what we are doing here doesn’t really need explanation but I’ll explain the axios part: we need the axios package to make POST/GET/PUT/PATCH etc requests to or from our laravel API, and Laravel is very keen on it’s CSRF-TOKEN for every server request to protect your web app from malicious individuals like myself 😈 check: <a href="https://laravel.com/docs/5.8/csrf">https://laravel.com/docs/5.8/csrf</a>, so we are basically sending the values of CSRF-TOKEN defined in the &lt;head&gt;&lt;/head&gt; of our app.blade.php with every axios request.</p><p>We’ll touch the PrivateRoute.js guy when the time comes but we need to install react-router-dom which provides the quite awesome routing system for React we talked about at the beginning of this article by running the command below in your terminal</p><pre>npm i react-router-dom</pre><h4>Router.js</h4><pre>import React from &#39;react&#39;;<br>import {BrowserRouter, Link, Route, Switch} from &#39;react-router-dom&#39;;</pre><pre>import Home from &#39;./components/Home/Home&#39;;<br>import Login from &#39;./views/Login/Login&#39;;<br>import Register from &#39;./views/Register/Register&#39;;<br>import NotFound from &#39;./views/NotFound/NotFound&#39;</pre><pre>// User is LoggedIn<br>import PrivateRoute from &#39;./PrivateRoute&#39;<br>import Dashboard from &#39;./views/user/Dashboard/Dashboard&#39;;</pre><pre>const Main = props =&gt; (</pre><pre>&lt;Switch&gt;<br>  {/*User might LogIn*/}<br>  &lt;Route exact path=&#39;/&#39; component={Home}/&gt;</pre><pre>  {/*User will LogIn*/}<br>  &lt;Route path=&#39;/login&#39; component={Login}/&gt;<br>  &lt;Route path=&#39;/register&#39; component={Register}/&gt;</pre><pre>  {/* User is LoggedIn*/}<br>  &lt;PrivateRoute path=&#39;/dashboard&#39; component={Dashboard}/&gt;</pre><pre>  {/*Page Not Found*/}<br>  &lt;Route component={NotFound}/&gt;</pre><pre>&lt;/Switch&gt;</pre><pre>);</pre><pre>export default Main;</pre><h4>Header.js</h4><pre>import React, {Component} from ‘react’<br>import {Link, withRouter} from &#39;react-router-dom&#39;;</pre><pre>class Header extends Component {<br>  // <strong>1.1</strong><br>  constructor(props) {<br>    super(props);<br>      this.state = {<br>        user: props.userData,<br>        isLoggedIn: props.userIsLoggedIn<br>      };<br>      this.logOut = this.logOut.bind(this);<br>  }</pre><pre>  // <strong>1.2</strong><br>  logOut() {<br>    let appState = {<br>      isLoggedIn: false,<br>      user: {}<br>    };<br>    localStorage[&quot;appState&quot;] = JSON.stringify(appState);<br>    this.setState(appState);<br>    this.props.history.push(&#39;/login&#39;);<br>  }</pre><pre>  // <strong>1.3</strong><br>  render() {<br>    const aStyle = {<br>      cursor: &#39;pointer&#39;<br>    };<br>    <br>    return (</pre><pre>&lt;nav className=&quot;navbar&quot;&gt;<br>        &lt;ul&gt;<br>          &lt;li&gt;&lt;Link to=&quot;/&quot;&gt;Index&lt;/Link&gt;&lt;/li&gt;<br>          {this.state.isLoggedIn ? <br>           &lt;li className=&quot;has-sub&quot;&gt;&lt;Link to=&quot;/dashboard&quot;&gt;Dashboard&lt;/Link&gt;&lt;/li&gt; : &quot;&quot;}<br>          {!this.state.isLoggedIn ?<br>            &lt;li&gt;&lt;Link to=&quot;/login&quot;&gt;Login&lt;/Link&gt; | &lt;Link to=&quot;/register&quot;&gt;Register&lt;/Link&gt;&lt;/li&gt; : &quot;&quot;}<br>        &lt;/ul&gt;<br>      &lt;/nav&gt;<br>    )<br>  }<br>}<br>export default withRouter(Header)</pre><p>I am sorry if my poorly commented code bothers you 😔, I’ll rather expatiate on the code instead — it doesn’t make the article unnecessarily complex; or does it? Well here goes;<br><strong>1.1</strong>. In the constructor, we create state user and isLoggedIn which derive data from a parent component or view (using props) — I guess you should already know all of this.<br><strong>1.2</strong>. We create a logout method to clear the data in localStorage we called appState (which would be created after successful user login or registration); <em>localStorage</em>? The answers here kinda do justice to that question: <a href="https://stackoverflow.com/questions/19867599/what-is-the-difference-between-localstorage-sessionstorage-session-and-cookies">https://stackoverflow.com/questions/19867599/what-is-the-difference-between-localstorage-sessionstorage-session-and-cookies</a><br><strong>1.3</strong>. This is rather self explanatory if you’ve done the right thing 😏</p><h4>Footer.js</h4><pre>import React from &#39;react&#39;;</pre><pre>const Footer = () =&gt; {<br>  return (<br>    &lt;footer&gt; <br>      Whatever normally goes into the footer   <br>    &lt;/footer&gt;<br>  )<br>};<br>export default Footer</pre><h4>Home.js</h4><pre>import React, {Component} from &#39;react&#39;<br>import Header from &#39;../Header/Header&#39;;<br>import Footer from &#39;../Footer/Footer&#39;;</pre><pre>class Home extends Component {<br>  constructor() {<br>    super();<br>    this.state = {<br>      isLoggedIn: false,<br>      user: {}<br>    }<br>  }</pre><pre>  // check if user is authenticated and storing authentication data as states if true<br>  componentWillMount() {<br>    let state = localStorage[&quot;appState&quot;];<br>    if (state) {<br>      let AppState = JSON.parse(state);<br>      this.setState({ isLoggedIn: AppState.isLoggedIn, user: AppState.user });<br>    }<br>  }</pre><pre>render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;Header userData={this.state.user} userIsLoggedIn={this.state.isLoggedIn}/&gt;<br>          &lt;span&gt;Whatever normally goes into the home/index page; <strong>A Plea To Heal The World</strong> for instance&lt;/span&gt;<br>        &lt;Footer/&gt;<br>      &lt;/div&gt;<br>      )<br>    }<br>  }</pre><pre>export default Home</pre><p>You could as well create the 404 page/NotFound yourself 😑</p><h4>RegisterContainer.js</h4><pre>import React, {Component} from &#39;react&#39;;<br>import {Link, withRouter} from &#39;react-router-dom&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br>import FlashMessage from &#39;react-flash-message&#39;;</pre><pre>class RegisterContainer extends Component {<br>  // <strong>2.1</strong><br>  constructor(props) {<br>    super(props);<br>    this.state = {<br>      isRegistered: false,<br>      error: &#39;&#39;,<br>      errorMessage: &#39;&#39;,<br>      formSubmitting: false,<br>      user: {<br>        name: &#39;&#39;,<br>        email: &#39;&#39;,<br>        password: &#39;&#39;,<br>        password_confirmation: &#39;&#39;,<br>    },<br>    redirect: props.redirect,<br>};<br>this.handleSubmit = this.handleSubmit.bind(this);<br>this.handleName = this.handleName.bind(this);<br>this.handleEmail = this.handleEmail.bind(this);<br>this.handlePassword = this.handlePassword.bind(this);<br>this.handlePasswordConfirm = this.handlePasswordConfirm.bind(this);<br>}</pre><pre>// <strong>2.2<br></strong>// componentWillMount, componentDidMount etc etc that have //componentStuffStuff are known as React Lifecycles which of course //you already know <br>componentWillMount() {<br>  let state = localStorage[&quot;appState&quot;];<br>  if (state) {<br>    let AppState = JSON.parse(state);<br>    this.setState({isLoggedIn: AppState.isLoggedIn, user: AppState});<br>  }<br>  if (this.state.isRegistered) {<br>    return this.props.history.push(&quot;/dashboard&quot;);<br>  }<br>}</pre><pre>// <strong>2</strong>.<strong>3</strong><br>componentDidMount() {<br>  const { prevLocation } = this.state.redirect.state || {prevLocation: { pathname: &#39;/dashboard&#39; } };<br>  if (prevLocation &amp;&amp; this.state.isLoggedIn) {<br>    return this.props.history.push(prevLocation);<br>  }<br>}</pre><pre>// <strong>2.4</strong><br>handleSubmit(e) {<br>  e.preventDefault();<br>  this.setState({formSubmitting: true});<br>  ReactDOM.findDOMNode(this).scrollIntoView();<br>  let userData = this.state.user;<br>  axios.post(&quot;/api/auth/signup&quot;, userData)<br>    .then(response =&gt; {<br>      return response;<br>  }).then(json =&gt; {<br>      if (json.data.success) {<br>        let userData = {<br>          id: json.data.id,<br>          name: json.data.name,<br>          email: json.data.email,<br>          activation_token: json.data.activation_token,<br>        };<br>        let appState = {<br>          isRegistered: true,<br>          user: userData<br>        };<br>        localStorage[&quot;appState&quot;] = JSON.stringify(appState);<br>        this.setState({<br>          isRegistered: appState.isRegistered,<br>          user: appState.user<br>        });<br>      } else {<br>          alert(`Our System Failed To Register Your Account!`);<br>      }<br> }).catch(error =&gt; {if (error.response) {<br>      // The request was made and the server responded with a status code that falls out of the range of 2xx<br>      let err = error.response.data;<br>      this.setState({<br>        error: err.message,<br>        errorMessage: err.errors,<br>        formSubmitting: false<br>      })<br>    }<br>    else if (error.request) {<br>      // The request was made but no response was received `error.request` is an instance of XMLHttpRequest in the browser and an instance of http.ClientRequest in node.js<br>      let err = error.request;<br>      this.setState({<br>        error: err,<br>        formSubmitting: false<br>      })<br>   } else {<br>       // Something happened in setting up the request that triggered an Error<br>       let err = error.message;<br>       this.setState({<br>         error: err,<br>         formSubmitting: false<br>       })<br>   }<br> }).finally(this.setState({error: &#39;&#39;}));<br>}</pre><pre>handleName(e) {<br>  let value = e.target.value;<br>  this.setState(prevState =&gt; ({<br>    user: {<br>      ...prevState.user, first_name: value<br>    }<br>  }));<br>}</pre><pre>// <strong>2.5</strong><br>handleEmail(e) {<br>  let value = e.target.value;<br>  this.setState(prevState =&gt; ({<br>    user: {<br>      ...prevState.user, email: value<br>    }<br>  }));<br>}</pre><pre>handlePassword(e) {<br>  let value = e.target.value;<br>  this.setState(prevState =&gt; ({<br>    user: {<br>      ...prevState.user, password: value<br>    }<br>  }));<br>}</pre><pre>handlePasswordConfirm(e) {<br>  let value = e.target.value;<br>  this.setState(prevState =&gt; ({<br>    user: {<br>      ...prevState.user, password_confirmation: value<br>    }<br>  }));<br>}</pre><pre>render() {<br>  // <strong>2.6</strong><br>  let errorMessage = this.state.errorMessage;<br>  let arr = [];<br>  Object.values(errorMessage).forEach((value) =&gt; (<br>    arr.push(value)<br>  ));</pre><pre>  return (<br>    &lt;div className=&quot;container&quot;&gt;<br>      &lt;div className=&quot;row&quot;&gt;<br>        &lt;div className=&quot;offset-xl-3 col-xl-6 offset-lg-1 col-lg-10 col-md-12 col-sm-12 col-12 &quot;&gt;<br>          &lt;h2&gt;Create Your Account&lt;/h2&gt;<br>         // <strong>2.7</strong><br>        {this.state.isRegistered ? &lt;FlashMessage duration={60000} persistOnHover={true}&gt;<br>          &lt;h5 className={&quot;alert alert-success&quot;}&gt;Registration successful, redirecting...&lt;/h5&gt;&lt;/FlashMessage&gt; : &#39;&#39;}<br>        {this.state.error ? &lt;FlashMessage duration={900000} persistOnHover={true}&gt;<br>          &lt;h5 className={&quot;alert alert-danger&quot;}&gt;Error: {this.state.error}&lt;/h5&gt;<br>          &lt;ul&gt;<br>            {arr.map((item, i) =&gt; (<br>              &lt;li key={i}&gt;&lt;h5 style={{color: &#39;red&#39;}}&gt;{item}&lt;/h5&gt;&lt;/li&gt;<br>             ))}<br>          &lt;/ul&gt;&lt;/FlashMessage&gt; : &#39;&#39;}</pre><pre>          &lt;form onSubmit={this.handleSubmit}&gt;<br>            &lt;div className=&quot;form-group&quot;&gt;<br>              &lt;input id=&quot;name&quot; type=&quot;text&quot; placeholder=&quot;Name&quot; className=&quot;form-control&quot; required onChange={this.handleName}/&gt;<br>            &lt;/div&gt;<br>            &lt;div className=&quot;form-group&quot;&gt;<br>              &lt;input id=&quot;email&quot; type=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;E-mail&quot; className=&quot;form-control&quot; required onChange={this.handleEmail}/&gt;<br>            &lt;/div&gt;<br>            &lt;div className=&quot;form-group&quot;&gt;<br>              &lt;input id=&quot;password&quot; type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;Password&quot; className=&quot;form-control&quot; required onChange={this.handlePassword}/&gt;<br>            &lt;/div&gt;<br>            &lt;div className=&quot;form-group&quot;&gt;<br>              &lt;input id=&quot;password_confirm&quot; type=&quot;password&quot; name=&quot;password_confirm&quot; placeholder=&quot;Confirm Password&quot; className=&quot;form-control&quot; required onChange={this.handlePasswordConfirm} /&gt;<br>            &lt;/div&gt;<br>            &lt;button type=&quot;submit&quot; name=&quot;singlebutton&quot; className=&quot;btn btn-default btn-lg  btn-block mb10&quot; disabled={this.state.formSubmitting ? &quot;disabled&quot; : &quot;&quot;}&gt;Create Account&lt;/button&gt;<br>          &lt;/form&gt;<br>          &lt;p className=&quot;text-white&quot;&gt;Already have an account?<br>            &lt;Link to=&quot;/login&quot; className=&quot;text-yellow&quot;&gt; Log In&lt;/Link&gt;<br>            &lt;span className=&quot;pull-right&quot;&gt;&lt;Link to=&quot;/&quot; className=&quot;text-white&quot;&gt;Back to Home&lt;/Link&gt;&lt;/span&gt;<br>        &lt;/p&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>    )<br>  }<br>}</pre><pre>// <strong>2.8</strong><br>export default withRouter(RegisterContainer);</pre><p>I hope you’re not bored at this moment, have a warm cup of coffee or choco to calm down, if you’re not already oversaturated. The RegisterContainerin this instance does all the logic of registering new users into our application. I won’t be explaining React lifecycles in this article as I assume you know that already<br><strong>2.1. </strong>I will talk more about the <em>redirect </em>when we explain Register.js (but you should know that we are getting the data of props.redirect from the parent i.e Register.js) or just research a lil here <a href="https://github.com/ReactTraining/history#navigation">https://github.com/ReactTraining/history#navigation</a><br><strong>2.2</strong>. Two actions are performed here: the first is to check if a localStorage called <em>appState </em>has been created either during registration or login processes and set those states with the values thereof, the second is to redirect the user to dashboard if he has been registered already.<br><strong>2.3. </strong>Well I guess I’ll touch a lil on <em>redirect </em>now; React nicely provides us with a way to navigate through history (more like back to where we came from), so for instance an unauthenticated user who visits <em>profile </em>and is directed to <em>login </em>or <em>register </em>should be automatically redirected back to <em>profile </em>on authentication — and not to <em>dashboard </em>or <em>any other page</em>. This is not necessary for our 3/4 views web app but it’s quite something cool to take note of.<br>Here we try to get the redirect to the previous location and if that is empty, return to the dashboard instead.<br><strong>2.4. </strong>scrollIntoView takes the user back to the top of the submitting form; axios.post does it’s job — sends the user data to our backend API and then create a localStorage called <em>appState </em>which stores the data. The rest handles errors.<br><strong>2.5. </strong>This explains the handleName, handleEmail, handlePassword and handlePasswordConfirm; they are called whenever the user enters values into the respective inputs which call them.<br><strong>2.6.</strong><strong> </strong>errorMessage takes the laravel validation error object (which are defined when of course there is a validation error; same with this.state.error) if any exists and pushes them to a defined array <em>arr </em>to enable us display them to the user in <strong>2.7<br>2.7. </strong>I forgot to add, <em>FlashMessage </em>is a another package used to unmount a component after a given delay which you can install by running</p><pre>yarn add react-flash-message<br>// or<br>npm i react-flash-message</pre><p>Check out the documentation at <a href="https://www.npmjs.com/package/react-flash-message">https://www.npmjs.com/package/react-flash-message</a> for more info.<br><strong>2.8. </strong>You shouldn’t have issues identifying <em>withRouter </em>if you have played your part, anyway it allows <em>this.props.history </em>to be accessible byRegisterContainer</p><h4>Register.js</h4><pre>import React, {Component} from &#39;react&#39;;<br>import RegisterContainer from &#39;./RegisterContainer&#39;;</pre><pre>class Register extends Component {<br>  constructor(props) {<br>    super(props);<br>    this.state = {<br>      redirect: props.location,<br>    }<br>  }</pre><pre>  render() {<br>    return (<br>      &lt;div className=&quot;content&quot;&gt;<br>        &lt;RegisterContainer redirect={this.state.redirect} /&gt;<br>      &lt;/div&gt;<br>    )<br>  }<br>}</pre><pre>export default Register</pre><p>We can access location data including history and a bunch of other data in react from props. We then pass this data from the dummy Register to the RegisterContainer check <strong>2.1 </strong>and <strong>2.3</strong></p><h4>LoginContainer</h4><pre>import React, {Component} from &#39;react&#39;;<br>import {Link, Redirect, withRouter} from &#39;react-router-dom&#39;;<br>import FlashMessage from &#39;react-flash-message&#39;;</pre><pre>class LoginContainer extends Component {</pre><pre>  constructor(props) {<br>    super(props);<br>    this.state = {<br>      isLoggedIn: false,<br>      error: &#39;&#39;,<br>      formSubmitting: false,<br>      user: {<br>        email: &#39;&#39;,<br>        password: &#39;&#39;,<br>      },<br>      redirect: props.redirect,<br>    };</pre><pre>    this.handleSubmit = this.handleSubmit.bind(this);<br>    this.handleEmail = this.handleEmail.bind(this);<br>    this.handlePassword = this.handlePassword.bind(this);<br>  }</pre><pre>  componentWillMount() {<br>    let state = localStorage[&quot;appState&quot;];<br>    if (state) {<br>      let AppState = JSON.parse(state);<br>      this.setState({isLoggedIn: AppState.isLoggedIn, user: AppState});<br>    }<br>  }</pre><pre>  componentDidMount() {<br>    const { prevLocation } = this.state.redirect.state || { prevLocation: { pathname: &#39;/dashboard&#39; } };<br>    if (prevLocation &amp;&amp; this.state.isLoggedIn) {<br>      return this.props.history.push(prevLocation);<br>    }<br>  }</pre><pre>  handleSubmit(e) {<br>    e.preventDefault();<br>    this.setState({formSubmitting: true});<br>    let userData = this.state.user;<br>    axios.post(&quot;/api/auth/login&quot;, userData).then(response =&gt; {<br>      return response;<br>    }).then(json =&gt; {<br>         if (json.data.success) {<br>           let userData = {<br>             id: json.data.id,<br>             name: json.data.name,<br>             email: json.data.email,<br>             access_token: json.data.access_token,<br>           };<br>           let appState = {<br>             isLoggedIn: true,<br>             user: userData<br>           };<br>           localStorage[&quot;appState&quot;] = JSON.stringify(appState);<br>           this.setState({<br>              isLoggedIn: appState.isLoggedIn,<br>              user: appState.user,<br>              error: &#39;&#39;<br>           });<br>           location.reload()<br>         }</pre><pre>         else {<br>            alert(`Our System Failed To Register Your Account!`);<br>         }<br>    }).catch(error =&gt; {if (error.response) {<br>        // The request was made and the server responded with a status code that falls out of the range of 2xx<br>        let err = error.response.data;<br>        this.setState({<br>          error: err.message,<br>          errorMessage: err.errors,<br>          formSubmitting: false<br>        })<br>      }<br>      else if (error.request) {<br>        // The request was made but no response was received `error.request` is an instance of XMLHttpRequest in the browser and an instance of http.ClientRequest in node.js<br>        let err = error.request;<br>        this.setState({<br>          error: err,<br>          formSubmitting: false<br>        })<br>     } else {<br>       // Something happened in setting up the request that triggered an Error<br>       let err = error.message;<br>       this.setState({<br>         error: err,<br>         formSubmitting: false<br>       })<br>   }<br> }).finally(this.setState({error: &#39;&#39;}));<br>}</pre><pre>handleEmail(e) {<br>  let value = e.target.value;<br>  this.setState(prevState =&gt; ({<br>    user: {<br>      ...prevState.user, email: value<br>    }<br>  }));<br>}</pre><pre>handlePassword(e) {<br>  let value = e.target.value;<br>  this.setState(prevState =&gt; ({<br>    user: {<br>      ...prevState.user, password: value<br>    }<br>  }));<br>}</pre><pre>render() {<br>  const { state = {} } = this.state.redirect;<br>  const { error } = state;</pre><pre>  return (<br>    &lt;div className=&quot;container&quot;&gt;<br>      &lt;div className=&quot;row&quot;&gt;<br>        &lt;div className=&quot;offset-xl-3 col-xl-6 offset-lg-1 col-lg-10 col-md-12 col-sm-12 col-12 &quot;&gt;<br>          &lt;h2 className=&quot;text-center mb30&quot;&gt;Log In To Your Account&lt;/h2&gt;<br>          {this.state.isLoggedIn ? &lt;FlashMessage duration={60000} persistOnHover={true}&gt;<br>          &lt;h5 className={&quot;alert alert-success&quot;}&gt;Login successful, redirecting...&lt;/h5&gt;&lt;/FlashMessage&gt; : &#39;&#39;}<br>          {this.state.error ? &lt;FlashMessage duration={100000} persistOnHover={true}&gt;<br>          &lt;h5 className={&quot;alert alert-danger&quot;}&gt;Error: {this.state.error}&lt;/h5&gt;&lt;/FlashMessage&gt; : &#39;&#39;}<br>          {error &amp;&amp; !this.state.isLoggedIn ? &lt;FlashMessage duration={100000} persistOnHover={true}&gt;<br>          &lt;h5 className={&quot;alert alert-danger&quot;}&gt;Error: {error}&lt;/h5&gt;&lt;/FlashMessage&gt; : &#39;&#39;}</pre><pre>          &lt;form onSubmit={this.handleSubmit}&gt;<br>            &lt;div className=&quot;form-group&quot;&gt;<br>              &lt;input id=&quot;email&quot; type=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;E-mail&quot; className=&quot;form-control&quot; required onChange={this.handleEmail}/&gt;<br>            &lt;/div&gt;<br>            &lt;div className=&quot;form-group&quot;&gt;<br>              &lt;input id=&quot;password&quot; type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;Password&quot; className=&quot;form-control&quot; required onChange={this.handlePassword}/&gt;<br>            &lt;/div&gt;<br>           &lt;button disabled={this.state.formSubmitting} type=&quot;submit&quot; name=&quot;singlebutton&quot; className=&quot;btn btn-default btn-lg  btn-block mb10&quot;&gt; {this.state.formSubmitting ? &quot;Logging You In...&quot; : &quot;Log In&quot;} &lt;/button&gt;<br>           &lt;/form&gt;</pre><pre>        &lt;/div&gt;</pre><pre>        &lt;p className=&quot;text-white&quot;&gt;Don&#39;t have an account? &lt;Link to=&quot;/register&quot; className=&quot;text-yellow&quot;&gt; Register&lt;/Link&gt;<br>          &lt;span className=&quot;pull-right&quot;&gt;<br>            &lt;Link to=&quot;/&quot; className=&quot;text-white&quot;&gt;Back to Index&lt;/Link&gt;<br>          &lt;/span&gt;<br>        &lt;/p&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>    )<br>  }<br>}</pre><pre>export default withRouter(LoginContainer);</pre><p>If you were able to successfully understand RegisterContainer you should easily get a grasp of this.</p><h4>Login.js</h4><pre>import React, {Component} from &#39;react&#39;;<br>import LoginContainer from &#39;./LoginContainer&#39;;<br>import {withRouter} from &quot;react-router-dom&quot;;</pre><pre>class Login extends Component {<br>  constructor(props) {<br>    super(props);<br>    this.state = {<br>      redirect: props.location,<br>    };<br>  }</pre><pre>  render() {<br>    return (<br>      &lt;div className=&quot;content&quot;&gt;<br>        &lt;LoginContainer redirect={this.state.redirect} /&gt;<br>      &lt;/div&gt;<br>    )<br>  } <br>}</pre><pre>export default withRouter(Login)</pre><h4>PrivateRoute.js</h4><pre>import React from &#39;react&#39;;<br>import {Redirect, Route, withRouter} from &#39;react-router-dom&#39;;</pre><pre>// <strong>3.1</strong><br>let state_of_state = localStorage[&quot;appState&quot;];<br>if (!state_of_state){<br>  let appState = {<br>    isLoggedIn: false,<br>    user: {}<br>  };<br>  localStorage[&quot;appState&quot;] = JSON.stringify(appState);<br>}</pre><pre>let state = localStorage[&quot;appState&quot;];<br>let AppState = JSON.parse(state);</pre><pre>// <strong>3.2</strong><br>const Auth = {<br>  isLoggedIn: AppState.isLoggedIn,<br>  user: AppState<br>};</pre><pre>// <strong>3.3</strong><br>const PrivateRoute = ({ component: Component, path, ...rest }) =&gt; (<br>&lt;Route path={path}<br>       {...rest}<br>       render={props =&gt; Auth.isLoggedIn ? (<br>       &lt;Component {...props} /&gt;) : (&lt;Redirect to={{<br>       pathname: &quot;/login&quot;,<br>       state: {<br>         prevLocation: path,<br>         error: &quot;You need to login first!&quot;,<br>       },<br>      }}<br>      /&gt;<br>    )<br>  }<br>/&gt;);</pre><pre>export default withRouter(PrivateRoute);</pre><p><strong>3.1. </strong>We need to make sure a localStorage[“appState”] exists to prevent a <em>JSON.stringify</em> parse error. if it doesn’t, we create empty data into it else we define the data as store and parse it into AppState <br><strong>3.2. </strong>This confirms if the user is authenticated by checking the value of the data in the defined AppState in <strong>3.1<br>3.3. </strong>This renders the component passed to the PrivateRoute in the Router if the user is authenticated or redirects to the Login with history data.</p><h4>Dashboard.js</h4><pre>import React, {Component} from &#39;react&#39;<br>import Header from &#39;../../../components/Header/Header&#39;;<br>import Footer from &#39;../../../components/Footer/Footer&#39;;</pre><pre>class Home extends Component {<br>  constructor() {<br>    super();<br>    this.state = {<br>      isLoggedIn: false,<br>      user: {}<br>    }<br>  }</pre><pre>// check if user is authenticated and storing authentication data as states if true<br>  componentWillMount() {<br>    let state = localStorage[&quot;appState&quot;];<br>    if (state) {<br>      let AppState = JSON.parse(state);<br>      this.setState({ isLoggedIn: AppState.isLoggedIn, user: AppState.user });<br>    }<br>  }</pre><pre>// <strong>4.1<br></strong>render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;Header userData={this.state.user} userIsLoggedIn={this.state.isLoggedIn}/&gt;<br>          &lt;span&gt;Whatever normally goes into the user dasboard page; <strong>the table below for instance</strong>&lt;/span&gt; &lt;br/&gt;<br>          &lt;table className=&quot;table table-striped&quot;&gt;<br>            &lt;tbody&gt;<br>              &lt;tr&gt;<br>                &lt;th scope=&quot;row &quot;&gt;User Id&lt;/th&gt;<br>                &lt;td&gt;{this.user.id}&lt;/td&gt;<br>              &lt;/tr&gt;<br>              &lt;tr&gt;<br>                &lt;th scope=&quot;row &quot;&gt;Full Name&lt;/th&gt;<br>                &lt;td&gt;{this.user.name}&lt;/td&gt;<br>              &lt;/tr&gt;<br>              &lt;tr&gt;<br>                &lt;th scope=&quot;row &quot;&gt;Email&lt;/th&gt;<br>                &lt;td&gt;{this.user.email}&lt;/td&gt;<br>              &lt;/tr&gt;<br>            &lt;/tbody&gt;<br>          &lt;/table&gt;<br>        &lt;Footer/&gt;<br>      &lt;/div&gt;<br>      )<br>    }<br>  }</pre><pre>export default Home</pre><p>Either one of the pages between Dashboard and Home was totally unnecessary due to the fact that both perform similar actions and totally make use of the same components and a simple authentication check could differentiate their respective actions and merge the two pages as one. The only reason for the duplication is to explain some concepts I forgot to add as I explain whatever the table up there is doing.<br><strong>4.1. </strong>In this render method, we create a simple table to display all the basic information of the authenticated user which are stored (during authentication) and then derived from localStorage[“appState”]</p><p><strong>A small confession:</strong> I snatched bits of the code here from the project I created (lazy/busy) and just edited away the unnecessary ones right here — so watch out for bugs and mistakes…looking back at the API tutorial URL I gave, I realized that the data returned from the Login and Registration APIs would definitely not go well with this tutorial; so here are a few workarounds to that:</p><h4>AuthController</h4><pre>&lt;?php</pre><pre>namespace App\Http\Controllers;</pre><pre>use Illuminate\Http\Request;<br>use Illuminate\Support\Facades\Auth;<br>use Carbon\Carbon;<br>use App\User;</pre><pre>class AuthController extends Controller<br>{<br>    /**<br>     * Create user<br>     *<br>     * ...<br>     */<br>    public function signup(Request $request)<br>    {<br>        ...  <br>    <br>        return response()-&gt;json([<br>            &#39;success&#39; =&gt; true,<br>            &#39;id&#39; =&gt; $user-&gt;id,<br>            &#39;name&#39; =&gt; $user-&gt;first_name,<br>            &#39;email&#39; =&gt; $user-&gt;email,<br>        ], 201);<br>    }<br>  <br>    /**<br>     * Login user and create token<br>     *<br>     * ...<br>     */<br>    public function login(Request $request)<br>    {<br>        ...</pre><pre>        return response()-&gt;json([<br>            &#39;success&#39; =&gt; true,<br>            &#39;id&#39; =&gt; $user-&gt;id,<br>            &#39;name&#39; =&gt; $user-&gt;first_name,<br>            &#39;email&#39; =&gt; $user-&gt;email,<br>            &#39;access_token&#39; =&gt; $tokenResult-&gt;accessToken,<br>            &#39;token_type&#39; =&gt; &#39;Bearer&#39;,<br>            &#39;expires_at&#39; =&gt; Carbon::parse(<br>                $tokenResult-&gt;token-&gt;expires_at<br>            )-&gt;toDateTimeString()<br>        ]);<br>    }<br>  <br>    ...<br>}</pre><h3>Conclusion</h3><p>I’ll wrap up here by saying this; Vue.js is just good enough for any SPA you want to create with Laravel — I’m just kind of an explorer and I guess exploration brought you here too.<br>This is just a skeletal structure for user authentication using React.js and Laravel; you can always add or subtract from it. 👌<br>If you find any bugs or lags or errors in any code snip above, feel free to comment or contact me. <strong><br>Repository: </strong><a href="https://github.com/000kelvin/laravel-react-authentication">Github</a></p><p><strong><em>Thank you very much for following till the very end, if you enjoyed this article in any way, clap for it. If you like me too, you can find me on </em></strong><a href="https://twitter.com/k_e_lv_i_n"><strong><em>twitter</em></strong></a><strong><em> — I actually don’t do much.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cfadf3194e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>