purity
purity

Reputation: 133

Flask login for REST API and Web application both

I want to do a Flask application with both REST API and Web Application. For example, my application will have protected routes:

And same protected routes but in REST API:

Now I want to implement register and login functions. I know that for Web Application part there is library Flask-Login for that purpose. For REST API part I know I can use Flask-JWT-Extended.

But, what if I want to make AJAX request from /notes/1 to /api/notes? To load all user notes on page after page load. I will need JWT token of user to make such request. Is it always neccessary to make request to /api/login first every time? Or I can use Flask-Login somehow to work using same JWT tokens REST API part uses and store JWT-tokens somewhere after user goes to page /notes/1 in his browser, allowing JS script to use it after page loading to make AJAX requests to protected API routes?

Upvotes: 1

Views: 176

Answers (0)

Related Questions