Skip to content

Commit 255b507

Browse files
authored
Merge pull request #25 from w3bdesign/development
Start work on Auth
2 parents 0136ca5 + a8ac071 commit 255b507

File tree

7 files changed

+62
-11
lines changed

7 files changed

+62
-11
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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/components/Layout/header.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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

frontend/src/context/AppContext.ts

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

frontend/src/lib/Auth.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,18 @@
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 = () => {};

frontend/src/pages/_app.tsx

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22

33
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

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

2544
export default App;

frontend/src/pages/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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

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)