Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

matt-sm/create-react-flask

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maintainability

create-react-app + flask

If you really want to create a client react app with session-based authentication.

It does seem counter-intuative to use a stateful server with a stateless Single Page App, but there may be situations (eg. required to integrate with an existing session-based Api) where you can't use tokens.

Notes:

  • for cookies to work, the Api must be hosted on the same domain as the site. On localhost, Api calls are be proxied to localhost:5000.
  • with the source of truth being the server, when the app first loads it tries to ping an endpoint to determine if the cookie is still valid, and set the correct lsLoggedIn value in state. The front end does not track cookie expiry, etc.
  • if isLoggedIn: true and the cookie does expire, the server will return a 401 and the app redux state will change to isLoggedIn: false

React structure inspired by this container pattern.

Auth managed via flask-login.

Redux actions/reducers based on login-flow.

Start the frontend:

cd client
nvm use
npm install
npm start

Start the backend:

virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
python run.py

Run prettier:

npm run prettier

About

An example of flask api integration with CRA

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.