-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example for React Native #34
Comments
Trying to use with react-native-router-flux., but:
Could you point me where location should be specified or may be I need to use something else than "Actions.replace" ?
|
Thanks for the note, I haven't used RNRF with redux-auth-wrapper but Im pretty interested in supporting this. It makes sense that you'd get a failed proptype there because its expecting to get the router location object and RNRF doesn't seem to give something like that. At some point we may need to provide some enhancer to pull RNRF routing specific data out to be used in a similar way. Provided you use the The replace of undefined is a bit more troubling, just looking at it without any context seems like @DveMac was the one who added support for RN, have you been using RNRF at all? |
Thank you for explanation. Now playing with |
@alexicum any insights/lessons learned you have into making this work would be greatly appreciated! |
I was aware of RNRF but not had chance to have a proper look - I will at some point, but for now I just using RR alone in my RN project and doing ugly transitions. The error @alexicum is seeing makes sense though as RNRF doesnt use 'history' like RR does. My gut feeling is it might require more that a few changes to add support to this project. |
@mjrussell I just updated my ReactNative project to v2.0.1, this is what I'm using package.json
index.[ios|android].js import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { createMemoryHistory } from 'history';
import { createStore, applyMiddleware, compose } from 'redux';
import { fromJS } from 'immutable';
import createSagaMiddleware from 'redux-saga';
import { combineReducers } from 'redux-immutable';
import { routerReducer, routerMiddleware, ConnectedRouter } from 'react-router-redux';
import { Route } from 'react-router-native';
import {
AppRegistry,
View,
} from 'react-native';
const history = createMemoryHistory({
initialEntries: ['/'],
});
const middlewares = [
createSagaMiddleware(),
routerMiddleware(history),
];
const enhancers = [
applyMiddleware(...middlewares),
];
const store = createStore(
combineReducers({
router: routerReducer, // other reducers here
}),
fromJS({}),
compose(...enhancers)
);
const LoginComponent = Login; // anyone can access this
const LogoutComponent = WithUserProfile(Logout); // wait for the profile to be loaded
const HomeComponent = Authenticated(EmailVerified(Home)); // must be authenticated and verified email
export class App extends Component {
render() {
return (
<Provider store={store}>
<ConnectedRouter history={history}>
<View>
{this.props.children}
<Switch>
<Route exact path="/" component={HomeComponent} />
<Route exact path="/login" component={LoginComponent} />
<Route exact path="/logout" component={LogoutComponent} />
</Switch>
</View>
</ConnectedRouter>
</Provider>
);
}
}
AppRegistry.registerComponent('BigChance', () => App); The auth wrappers are defined as // Library
import connectedAuthWrapper from 'redux-auth-wrapper/connectedAuthWrapper';
import { connectedReduxRedirect } from 'redux-auth-wrapper/history4/redirect';
import { replace } from 'react-router-redux';
// Project
import {
makeSelectIsLoggedIn,
makeSelectIsInitializingAuth,
makeSelectIsEmailVerified,
} from 'app/containers/Auth/selectors';
import LoadingPage from 'app/components/LoadingPage';
const initialising = makeSelectIsInitializingAuth();
const afterInit = (check = () => true) => (state) => (initialising(state) === false && check(state));
export const Authenticated = connectedReduxRedirect({
wrapperDisplayName: 'Authenticated',
authenticatedSelector: afterInit(makeSelectIsLoggedIn()),
authenticatingSelector: initialising,
AuthenticatingComponent: LoadingPage,
redirectPath: '/logout',
redirectAction: replace,
allowRedirectBack: true,
});
export const EmailVerified = connectedReduxRedirect({
wrapperDisplayName: 'EmailVerified',
authenticatedSelector: afterInit(makeSelectIsEmailVerified()),
authenticatingSelector: initialising,
AuthenticatingComponent: LoadingPage,
redirectPath: '/not-verified',
redirectAction: replace,
allowRedirectBack: true,
});
export const WithUserProfile = connectedAuthWrapper({
wrapperDisplayName: 'WithUserProfile',
authenticatedSelector: afterInit(),
authenticatingSelector: initialising,
AuthenticatingComponent: LoadingPage,
FailureComponent: LoadingPage,
}); |
@piuccio I think you forgot |
You're right |
I vote on @piuccio example to be part of redux-auth-wrapper examples for React Native, I'm using on two projects here without any trouble. |
#33 implements React Native support. React-router doesn't support native but there is a lot of good things being said about https://github.com/aksonov/react-native-router-flux.
Should create a basic React Native app, the auth wrappers should look almost identical except will need to override the redirectAction with a redux action.
The text was updated successfully, but these errors were encountered: