File tree Expand file tree Collapse file tree 7 files changed +62
-11
lines changed Expand file tree Collapse file tree 7 files changed +62
-11
lines changed Original file line number Diff line number Diff line change 99 },
1010 "dependencies" : {
1111 "@apollo/client" : " ^3.1.4" ,
12+ "@types/js-cookie" : " ^2.2.6" ,
1213 "axios" : " ^0.20.0" ,
1314 "bootstrap" : " ^4.5.2" ,
1415 "graphql" : " ^15.3.0" ,
Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ const Header = () => (
1818 < Nav . Link href = "/register" > Register</ Nav . Link >
1919 </ Link >
2020 </ Nav >
21+ < Nav className = "justify-content-center" >
22+ User:
23+ </ Nav >
24+
2125 </ Navbar >
2226) ;
2327
Original file line number Diff line number Diff line change 1+ import { createContext } from 'react' ;
2+
3+ // const AppContext = createContext({ user: null, isAuthenticated: false, setUser: null });
4+ const AppContext = createContext ( { } ) ;
5+
6+ export default AppContext ;
Original file line number Diff line number Diff line change 22// https://strapi.io/blog/nextjs-react-hooks-strapi-auth-4
33// https://flaviocopes.com/nextjs-cookies/
44// https://medium.com/@enetoOlveda /how-to-use-axios-typescript-like-a-pro-7c882f71e34a
5+
6+ const API_URL = process . env . NEXT_PUBLIC_API_URL || 'http://localhost:1338/graphql' ;
7+
8+ console . log ( API_URL ) ;
9+
10+ export const Login = ( ) => {
11+ if ( typeof window === 'undefined' ) {
12+ console . log ( 'Server login!' ) ;
13+ }
14+ return 'Logging in ...' ;
15+ } ;
16+
17+ export const Register = ( ) => { } ;
18+
19+ export const Logout = ( ) => { } ;
Original file line number Diff line number Diff line change 1- import React from 'react' ;
1+ import React , { useState } from 'react' ;
22
33import type { AppProps /* , AppContext */ } from 'next/app' ;
44
55import Head from 'next/head' ;
66import { ApolloProvider } from '@apollo/client' ;
7+ import Cookie from 'js-cookie' ;
8+ import fetch from 'axios' ;
79
10+ import AppContext from '../context/AppContext' ;
811import client from '../lib/Apollo' ;
912import Header from '../components/Layout/header' ;
1013import Footer from '../components/Layout/footer' ;
1114
1215import 'bootstrap/dist/css/bootstrap.min.css' ;
1316
14- const App = ( { Component } : AppProps ) => (
15- < div >
16- < Head > < title > Food ordering fullstack application with NextJS and Strapi</ title > </ Head >
17- < Header />
18- < ApolloProvider client = { client } >
19- < Component />
20- </ ApolloProvider >
21- < Footer />
22- </ div >
23- ) ;
17+ const App = ( { Component } : AppProps ) => {
18+ const [ user , setUser ] = useState ( null ) ;
19+
20+ return (
21+ < >
22+ < Head >
23+ < title >
24+ Food ordering fullstack application with NextJS and Strapi
25+ </ title >
26+ </ Head >
27+ < AppContext . Provider
28+ value = { {
29+ user,
30+ isAuthenticated : ! ! user ,
31+ setUser,
32+ } }
33+ >
34+ < Header />
35+ < ApolloProvider client = { client } >
36+ < Component />
37+ </ ApolloProvider >
38+ </ AppContext . Provider >
39+ < Footer />
40+ </ >
41+ ) ;
42+ } ;
2443
2544export default App ;
Original file line number Diff line number Diff line change 11// https://nextjs.org/docs/basic-features/typescript
22// https://strapi.io/blog/nextjs-react-hooks-strapi-restaurants-2
33// https://strapi.io/blog/nextjs-react-hooks-strapi-dishes-3
4+ // https://strapi.io/blog/nextjs-react-hooks-strapi-auth-4
45
56// Bootstrap:
67
Original file line number Diff line number Diff line change 13641364 resolved "https://registry.yarnpkg.com/@types/invariant/-/invariant-2.2.34.tgz#05e4f79f465c2007884374d4795452f995720bbe"
13651365 integrity sha512-lYUtmJ9BqUN688fGY1U1HZoWT1/Jrmgigx2loq4ZcJpICECm/Om3V314BxdzypO0u5PORKGMM6x0OXaljV1YFg==
13661366
1367+ " @types/js-cookie@^2.2.6 " :
1368+ version "2.2.6"
1369+ resolved "https://registry.yarnpkg.com/@types/js-cookie/-/js-cookie-2.2.6.tgz#f1a1cb35aff47bc5cfb05cb0c441ca91e914c26f"
1370+ integrity sha512-+oY0FDTO2GYKEV0YPvSshGq9t7YozVkgvXLty7zogQNuCxBhT9/3INX9Q7H1aRZ4SUDRXAKlJuA4EA5nTt7SNw==
1371+
13671372" @types/json-schema@^7.0.3" , "@types/json-schema@^7.0.5":
13681373 version "7.0.6"
13691374 resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
You can’t perform that action at this time.
0 commit comments