Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange login flow examples in Redux-Saga documentation

For example, if you read this section in redux-saga`s documentation there is an example related to login flow that looks like this.

function* loginFlow() {
  while (true) {
    yield take('LOGIN')
    // ... perform the login logic
    yield take('LOGOUT')
    // ... perform the logout logic
  }
} 

As there said:

The loginFlow Saga more clearly conveys the expected action sequence. It knows that the LOGIN action should always be followed by a LOGOUT action, and that LOGOUT is always followed by a LOGIN

Does LOGOUT always follow LOGIN ? I dont think so. For example, when user logged in to web site once, as usual, session will be stored in cookies of web site and when user will visit this web site again how loginFlow saga will catch LOGOUT action?

Or, next example, with login again that described here. I wonder how user can click LOGOUT if authorization not completed yet and button that log user out of web site not showed yet? These examples sound strange. I confused a little bit.

Can anyone explain me how these examples fit real world situations of login flow?

Thanks.

like image 445
Emil Avatar asked Mar 02 '18 23:03

Emil


1 Answers

The saga will only run when an Action/or Actions are associated with it. For Example You have a button which dispatches actions with type {type:"LOGIN_LOGOUT", data}. Now assume only when this action dispatches the above saga gets called. If logged in it will logout and vice versa, hence the example.

like image 183
Karan Jariwala Avatar answered Oct 21 '22 11:10

Karan Jariwala