├── .gitignore
├── package.json
├── public
└── index.html
├── src
├── App.tsx
├── contexts
│ └── auth.tsx
├── index.tsx
├── pages
│ ├── Home
│ │ └── index.tsx
│ └── Login
│ │ └── index.tsx
├── react-app-env.d.ts
├── routes
│ ├── OtherRoutes.tsx
│ ├── SignRoutes.tsx
│ └── index.tsx
└── services
│ └── api.ts
├── tsconfig.json
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "authapp",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^4.2.4",
7 | "@testing-library/react": "^9.3.2",
8 | "@testing-library/user-event": "^7.1.2",
9 | "@types/jest": "^24.0.0",
10 | "@types/node": "^12.0.0",
11 | "@types/react": "^16.9.0",
12 | "@types/react-dom": "^16.9.0",
13 | "react": "^16.13.1",
14 | "react-dom": "^16.13.1",
15 | "react-router-dom": "^5.2.0",
16 | "react-scripts": "3.4.3",
17 | "typescript": "~3.7.2"
18 | },
19 | "scripts": {
20 | "start": "react-scripts start",
21 | "build": "react-scripts build",
22 | "test": "react-scripts test",
23 | "eject": "react-scripts eject"
24 | },
25 | "eslintConfig": {
26 | "extends": "react-app"
27 | },
28 | "browserslist": {
29 | "production": [
30 | ">0.2%",
31 | "not dead",
32 | "not op_mini all"
33 | ],
34 | "development": [
35 | "last 1 chrome version",
36 | "last 1 firefox version",
37 | "last 1 safari version"
38 | ]
39 | },
40 | "devDependencies": {
41 | "@types/react-router-dom": "^5.1.5"
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 | React App
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/App.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Routes from './routes';
3 | import { AuthProvider } from './contexts/auth';
4 |
5 | function App() {
6 | return (
7 |
12 | );
13 | }
14 |
15 | export default App;
16 |
--------------------------------------------------------------------------------
/src/contexts/auth.tsx:
--------------------------------------------------------------------------------
1 | import React, { createContext, useState, useEffect, useContext } from 'react';
2 |
3 | import * as api from '../services/api';
4 |
5 | interface AuthContextData {
6 | signed: boolean;
7 | user: object | null;
8 | Login(user: object): Promise;
9 | Logout(): void;
10 | }
11 |
12 | const AuthContext = createContext({} as AuthContextData);
13 |
14 | export const AuthProvider: React.FC = ({ children }) => {
15 | const [user, setUser] = useState