H
H
Hlib2019-06-15 22:25:03
Flask
Hlib, 2019-06-15 22:25:03

How to make a full Flask + React login?

I have a form where you can log in a user, and if the data exists in the database, then the session key will be returned in response
. And then the very essence of the question appears, what should I do with it? How to use a session key so that a user can log into the network and write on his own behalf and edit only his profile?
There is some material for understanding how to implement a full-fledged login

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2019-06-16
@Mysianio

1. Upon successful authorization, send a token to the client.
2. Store the token in a cookie. Check for its presence during initialization and either render the variant for the logged in user after downloading his data, or for the guest.
3. Having data such as user id, you can easily distinguish whether you should show the edit button in your profile or not:

const { me, user } = this.props;
const isOwner = me.id === user.id;

return (
  <>
    {isOwner && <Button onClick={this.handleEditClick}>Edit</Button>}
    {/* other jsx */}
  </>
);

where me is the currently logged in user, user is the user whose profile is loaded.
4. Of course, all rights must be checked on the server side. To do this, the token should be sent in the request headers.
Material on the Internet on the topic of the sea, just open Google and make the desired request. Naturally, there are no articles and manuals that contain all cases without exception, so study different sources.

D
Dmitry Sviridov, 2019-06-16
@dimuska139

Upon successful authorization, generate and return a jwt-token from the server in which the user data and access rights will be embedded. Based on this information, already at the front, determine what needs to be rendered and what not. For each request to the server, pass this jwt token in the header, and validate it there. If valid, then see the rights sewn into it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question