Build a Mini Netflix (with React)
  • About Cloudinary Labs
  • Build a Mini Netflix with Cloudinary
    • Introduction
    • Delivering Video
    • Setup React
    • Install Dependencies
    • Styling your App
    • User Authentication
    • Callback Component
    • Navigation Component
    • Display Component
    • Setup Root Route
    • Upload Component
    • Setup Upload Route
    • Upload Videos
    • Display Videos
    • Enable Auth
    • Share on Twitter
Powered by GitBook
On this page
  • Add Callback route
  • Restrict Upload route
  1. Build a Mini Netflix with Cloudinary

Enable Auth

The last steps of this code lab involves restricting the uploading of videos to registered users only.

The first step is to add the callback route to the list of routes. The second step is to restrict the upload route to registered users.

Add Callback route

Modify your routes in src/index.js to be like this:

import React from 'react';
import ReactDOM from 'react-dom';
import Upload from './components/Upload';
import Display from './components/Display';
import Callback from './components/Callback';
import registerServiceWorker from './registerServiceWorker';
import { Router, Route, browserHistory } from 'react-router';
import { requireAuth } from './utils/AuthService';

const Root = () => {
  return (
    <div className="container">
      <Router history={browserHistory}>
        <Route path="/" component={Display}/>
        <Route path="/upload" component={Upload} />
        <Route path="/callback" component={Callback} />
      </Router>
    </div>
  )
}

ReactDOM.render(<Root />, document.getElementById('root'));
registerServiceWorker();

Restrict Upload route

Modify your routes in src/index.js to be like this:

import React from 'react';
import ReactDOM from 'react-dom';
import Upload from './components/Upload';
import Display from './components/Display';
import Callback from './components/Callback';
import registerServiceWorker from './registerServiceWorker';
import { Router, Route, browserHistory } from 'react-router';
import { requireAuth } from './utils/AuthService';

const Root = () => {
  return (
    <div className="container">
      <Router history={browserHistory}>
        <Route path="/" component={Display}/>
        <Route path="/upload" component={Upload} onEnter={requireAuth} />
        <Route path="/callback" component={Callback} />
      </Router>
    </div>
  )
}

ReactDOM.render(<Root />, document.getElementById('root'));
registerServiceWorker();

Now, users won't be able to upload videos until they are registered on your app.

PreviousDisplay VideosNextShare on Twitter

Last updated 7 years ago