user log in finished
This commit is contained in:
parent
18ebca4c0a
commit
4e6b393b23
|
@ -22,28 +22,36 @@ http {
|
|||
proxy_set_header X-Forwarded-Ssl on; # Optional
|
||||
proxy_set_header X-Forwarded-Port $server_port;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
|
||||
# proxy_set_header X-Forwarded-Host $server_name;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://server:8000;
|
||||
proxy_set_header X-Real_IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-NginX-Proxy true;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_pass_header Set-Cookie;
|
||||
rewrite ^/api(.*)$ $1 break;
|
||||
proxy_pass http://server:8000;
|
||||
}
|
||||
|
||||
location /cable {
|
||||
proxy_pass http://server:8000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
# rewrite ^/cable(.*)$ $1 break;
|
||||
}
|
||||
# location /cable {
|
||||
# proxy_pass http://server:8000;
|
||||
# proxy_http_version 1.1;
|
||||
# proxy_set_header Upgrade $http_upgrade;
|
||||
# proxy_set_header Connection "upgrade";
|
||||
# proxy_pass_header Set-Cookie;
|
||||
# # rewrite ^/cable(.*)$ $1 break;
|
||||
# }
|
||||
|
||||
location /socksjs-node {
|
||||
proxy_pass http://server:8000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
# rewrite ^/cable(.*)$ $1 break;
|
||||
}
|
||||
# location /socksjs-node {
|
||||
# proxy_pass http://server:8000;
|
||||
# proxy_http_version 1.1;
|
||||
# proxy_set_header Upgrade $http_upgrade;
|
||||
# proxy_set_header Connection "upgrade";
|
||||
# # rewrite ^/cable(.*)$ $1 break;
|
||||
# }
|
||||
}
|
||||
}
|
|
@ -19,8 +19,8 @@ services:
|
|||
context: ./frontend
|
||||
volumes:
|
||||
- ./frontend/src:/usr/src/frontend/src
|
||||
ports:
|
||||
- 3000:3000
|
||||
# ports:
|
||||
# - 3000:3000
|
||||
environment:
|
||||
CHOKIDAR_USEPOLLING: "true"
|
||||
REACT_APP_API_URL: "/api"
|
||||
|
|
|
@ -1,46 +1 @@
|
|||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `yarn start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `yarn test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `yarn build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `yarn eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
# CASHSTACKS
|
||||
|
|
22667
frontend/package-lock.json
generated
22667
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -21,6 +21,11 @@ export const AppContextProvider = ({ children, baseURL }: Props) => {
|
|||
|
||||
api.interceptors.request.use((config) => {
|
||||
// config.url += '?format=json'
|
||||
config.headers = {
|
||||
Authorization: `Token ${window.localStorage.getItem(
|
||||
'cash-stacks-token',
|
||||
)}`,
|
||||
}
|
||||
return config
|
||||
})
|
||||
|
||||
|
|
|
@ -23,16 +23,20 @@ export const UserContextProvider = ({ children }: Props) => {
|
|||
|
||||
const [user, setUser] = useState<User | null>(null)
|
||||
|
||||
const handleLogin = async (name: string, password: string) => {
|
||||
console.log('logging in?', name, password)
|
||||
|
||||
const handleLogin = async (username: string, password: string) => {
|
||||
try {
|
||||
const { id } = await api.post<any, { id: string }>('/login', {
|
||||
name,
|
||||
password,
|
||||
})
|
||||
if (!id) throw new Error('Problem logging in!')
|
||||
const user = await api.get<User>(`/users/${id}`)
|
||||
const { key } = await api.post<any, { key: string }>(
|
||||
'/dj-rest-auth/login/',
|
||||
{
|
||||
username,
|
||||
password,
|
||||
},
|
||||
)
|
||||
if (!key) throw new Error('Problem logging in!')
|
||||
window.localStorage.setItem('cash-stacks-token', key)
|
||||
const user = await api.get<User>(`/dj-rest-auth/user/`)
|
||||
|
||||
console.log('user', user)
|
||||
|
||||
if (!user) message.error(`Couldn't find user`)
|
||||
setUser(user)
|
||||
|
|
|
@ -4,21 +4,18 @@ import { Link } from 'react-router-dom'
|
|||
import { Form } from '../../elements/Form'
|
||||
import { Button } from '../../elements/Button'
|
||||
import { useForm } from 'antd/lib/form/Form'
|
||||
import { useAppContext } from '../../contexts/AppContext'
|
||||
import { useUserContext } from '../../contexts/UserContext'
|
||||
|
||||
type FormValues = { username: string; password: string }
|
||||
|
||||
export const Login = () => {
|
||||
const appContext = useAppContext()
|
||||
const userContext = useUserContext()
|
||||
|
||||
const [form] = useForm<FormValues>()
|
||||
|
||||
const handleFinish = async ({ username, password }: FormValues) => {
|
||||
try {
|
||||
const res = await appContext.post('/dj-rest-auth/login/', {
|
||||
username,
|
||||
password,
|
||||
})
|
||||
const res = await userContext.handleLogin(username, password)
|
||||
console.log('logging in', res)
|
||||
} catch (err) {
|
||||
console.log('error logging in')
|
||||
|
|
3007
frontend/yarn.lock
3007
frontend/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user