This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* /pages/restaurants.js */ | |
import gql from "graphql-tag"; | |
import { withRouter } from "next/router"; | |
import { graphql } from "react-apollo"; | |
import { compose } from "recompose"; | |
import { withContext } from "../components/Context/AppProvider"; | |
import { | |
Button, | |
Card, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* server.js */ | |
const express = require('express') | |
const next = require('next') | |
const dev = process.env.NODE_ENV !== 'production' | |
const app = next({ dev }) | |
const handle = app.getRequestHandler() | |
app.prepare() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* hocs/defaultPage.js */ | |
import React from "react"; | |
import Router from "next/router"; | |
import { getUserFromServerCookie, getUserFromLocalCookie } from "../lib/auth"; | |
export default Page => | |
class DefaultPage extends React.Component { | |
static async getInitialProps({ req }) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* components/hocs/securePage.js */ | |
import React from "react"; | |
import PropTypes from "prop-types"; | |
import defaultPage from "./defaultPage"; | |
const securePageHoc = Page => | |
class SecurePage extends React.Component { | |
static propTypes = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* /lib/auth.js */ | |
import jwtDecode from "jwt-decode"; | |
import Cookies from "js-cookie"; | |
import Strapi from "strapi-sdk-javascript/build/main"; | |
import Router from "next/router"; | |
const apiUrl = process.env.API_URL || "http://localhost:1337"; | |
const strapi = new Strapi(apiUrl); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* /pages/signup.js */ | |
import React from "react"; | |
import { strapiRegister } from "../lib/auth"; | |
import Router from "next/router"; | |
import { | |
Container, | |
Row, | |
Col, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* /pages/signin.js */ | |
import React from "react"; | |
import defaultPage from "../hocs/defaultPage"; | |
import { strapiLogin } from "../lib/auth"; | |
import Router from "next/router"; | |
import { | |
Container, | |
Row, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { unsetToken } from "../lib/auth"; | |
class Layout extends React.Component { | |
render() { | |
const { isAuthenticated, children } = this.props; | |
return ( | |
<div> | |
<header> | |
<Nav className="navbar navbar-dark bg-dark"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* components/Cart/Cart.js */ | |
import React from "react"; | |
import defaultPage from "../../hocs/defaultPage"; | |
import { withContext } from "../Context/AppProvider"; | |
import { compose } from "recompose"; | |
import Link from "next/link"; | |
import { withRouter } from "next/router"; | |
import { | |
Button, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* /components/Context/AppProvider */ | |
import React from "react"; | |
import Cookies from "js-cookie"; | |
/* First we will make a new context */ | |
const AppContext = React.createContext(); | |
/* Then create a provider Component */ | |
class AppProvider extends React.Component { | |
constructor(props) { |