Skip to content

Commit 4709ecb

Browse files
committed
Add AppContext provider
1 parent 34412e4 commit 4709ecb

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
"build": "next build",
55
"start": "next start",
66
"eslint": "eslint --fix src/**/*",
7-
"types:generate": "apollo codegen:generate --target typescript --excludes=node_modules/* --includes=**/*.tsx --endpoint http://localhost:1338/graphql --tagName=gql --outputFlat src/generatedTypes --passthroughCustomScalars --customScalarsPrefix Restaurants",
7+
"types:generate": "apollo codegen:generate --target typescript --excludes=node_modules/* --includes=**/*.tsx --endpoint http://localhost:1338/graphql --tagName=gql --outputFlat src/generatedTypes --passthroughCustomScalars --customScalarsPrefix Restaurants",
88
"schema:download": "apollo schema:download --endpoint http://localhost:1338/graphql"
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",

frontend/src/context/AppContext.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createContext } from 'react';
2+
3+
const AppContext = createContext({ isAuthenticated: false });
4+
5+
export default AppContext;

frontend/src/lib/Auth.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:1338/graphq
77

88
console.log(API_URL);
99

10-
export const Login = () => {};
10+
export const Login = () => {
11+
if (typeof window === 'undefined') {
12+
console.log('Server login!');
13+
}
14+
return 'Logging in ...';
15+
};
1116

1217
export const Register = () => {};
1318

frontend/src/pages/_app.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,36 @@ import type { AppProps /* , AppContext */ } from 'next/app';
44

55
import Head from 'next/head';
66
import { ApolloProvider } from '@apollo/client';
7+
import Cookie from 'js-cookie';
8+
import fetch from 'axios';
79

10+
import AppContext from '../context/AppContext';
811
import client from '../lib/Apollo';
912
import Header from '../components/Layout/header';
1013
import Footer from '../components/Layout/footer';
1114

1215
import 'bootstrap/dist/css/bootstrap.min.css';
1316

1417
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>
18+
<>
19+
<Head>
20+
<title>Food ordering fullstack application with NextJS and Strapi</title>
21+
</Head>
22+
<AppContext.Provider
23+
value={{
24+
user: 'no-user',
25+
// isAuthenticated: !!this.state.user,
26+
isAuthenticated: false,
27+
// setUser: this.setUser,
28+
}}
29+
>
30+
<Header />
31+
<ApolloProvider client={client}>
32+
<Component />
33+
</ApolloProvider>
34+
</AppContext.Provider>
2135
<Footer />
22-
</div>
36+
</>
2337
);
2438

2539
export default App;

frontend/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,11 @@
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"

0 commit comments

Comments
 (0)