G
G
Geckyhit2018-09-06 12:56:57
JavaScript
Geckyhit, 2018-09-06 12:56:57

Where to put the authorization logic?

Good afternoon, I hope knowledgeable people will answer me. In general, look, the react + redux project has some kind of authorization logic (we check cookies for a token, send it to the server and get user data) and put them in the store (depending on this, the UI of the components changes a lot). Where is the best place to put this logic? I thought 1. Make a certain init module that executes this logic and directly dispatches it to the store 2. Push it into the middleware, but what's the point if the logic is executed only once, that is, before launching 3. Your option ??? thanks in advance for your attention

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-09-06
@Geckyhit

For example like this:

import React from 'react';
import { render } from 'react-dom';
import configureStore from './store';

const store = configureStore();

store.dispatch(init());

render(
  <Provider store={store}>
    <Router>
      <App />
    </Router>
  </Provider>,
  document.getElementById('root')
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question