Using generateRequireSignInWrapper throws error
See original GitHub issueUsing the generateRequireSignInWrapper gives me this error message:
Could not find “store” in either the context or props of “Connect(GatedPage)”. Either wrap the root component in a Provider, or explicitly pass “store” as a prop to “Connect(GatedPage)”.
Here is my code:
index.js
import React from "react";
import ReactDOM from "react-dom";
import { createStore, applyMiddleware, compose } from "redux";
import { Provider } from "react-redux";
import reduxThunk from "redux-thunk";
import { verifyCredentials } from "./apis/redux-token-auth-config";
import reducers from "./reducers";
import App from "./components/App";
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(
reducers,
composeEnhancers(applyMiddleware(reduxThunk))
);
verifyCredentials(store);
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("root")
);
app.js
import React from "react";
import "semantic-ui-css/semantic.min.css";
import { Router, Route, Switch } from "react-router-dom";
import history from "../history";
import { generateRequireSignInWrapper } from "redux-token-auth";
import LandingPage from "./LandingPage";
import CardCreate from "./CardsCreate";
import CardShow from "./CardShow";
import SignInPage from "./SignInPage";
const requireSignIn = generateRequireSignInWrapper({
redirectPathIfNotSignedIn: "/signin"
});
const Routes = () => (
<div className="ui container">
<Router history={history}>
<div>
<Switch>
<Route path="/" exact component={requireSignIn(LandingPage)} />
<Route path="/cards/new" exact component={CardCreate} />
<Route path="/cards/:id" exact component={CardShow} />
<Route path="/signin" exact component={SignInPage} />
</Switch>
</div>
</Router>
</div>
);
const App = () => {
return Routes();
};
export default App;
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
How to Generate Your Own Error Messages in R - dummies
You can tell R to throw an error by inserting the stop() function anywhere in the body of the function, as in the...
Read more >Issues - redux-token-auth - kylecorbelli - Geeks
Redux actions and reducers to integrate easily with Devise Token Auth - kylecorbelli. ... Using generateRequireSignInWrapper throws error.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@tochman I threw out this module and implemented my own middleware instead:
Then I applied it to store in root index.js:
Then in authActions i made the following function:
The setHeaders function just relays the headers that gets returned from the rails app to the middleware (via the action key), so that they are always available to the axios module (needed for every request).
Then you can make your own custom protected routes (assuming you are using react-router-dom), in which I call the validateUser action in ComponentDidMount. For my part I made three custom routes. AdminRoute, ProtectedRoute (for signed in users) and AuthRoute (which automatically redirects a signed in user away from the signup page). The syntax is a little obscure but here is the ProtectedRoute.js:
You can probably omit IsDOMLoaded. Don’t remember why I included that.
Then in your app.js where you define your routes:
Awesome solution.