1.0.10 • Published 7 years ago
redux-auth0 v1.0.10
Redux Auth0 middleware
In the project directory, you can run:
yarn add redux-auth0
(or npm install redux-auth0
)
Initialise your store:
import { combineReducers, applyMiddleware, compose } from 'redux';
import auth0 from 'redux-auth0';
const { createStore: createStoreWithAuth0, middleware:auth0middleware, reducer: auth } = auth0({
domain: 'your-domain.auth0.com',
clientID: 'YOUR_CLIENT_ID',
redirectUri: 'http://your-allowed/callback',
audience: 'https://your-domain.auth0.com/userinfo',
responseType: 'token id_token',
scope: 'token openid',
});
const middlewares = [/*any middleware*/, auth0middleware];
//Use redux-auth0 createStore
const store = createStoreWithAuth0(
combineReducers({
/* any reducer */
auth,
}),
compose(
/* any enhancers */
applyMiddleware(...middlewares),
/*...*/
)
);
Username password authentication
store.dispatch(
loginUsernamePassword({
username: 'john.doe@mail.com',
password: 'password',
realm: 'YourAuth0Database',
//optional action dispatched on user login:
redirect: {type: 'ANY_ACTION'}
})
);
Login with google
store.dispatch(socialConnection({ connection: 'google-oauth2'}));
On social connection success, you'll be redirected to the callback url configure above, so you have to parse the url to recover your token.
For example, with redux-first-router, you will have something like so:
import { handleLogin, handleAuthentication } from 'redux-auth0';
const routes = {
PRIVATE_ROUTE: '/private',
AUTHORIZE: {
path: '/callback',
thunk: async (dispatch) => {
try {
const authResult = await handleAuthentication();
dispatch(handleLogin(authResult));
dispatch({ type: 'PRIVATE_ROUTE' });
} catch (error) {
/* ... */
}
}
},
}
1.0.10
7 years ago
1.0.9-rc
7 years ago
1.0.8-rc
7 years ago
1.0.7-rc
7 years ago
1.0.6-rc
7 years ago
1.0.5
7 years ago
1.0.5-rc
7 years ago
1.0.4-rc
7 years ago
1.0.3-rc
7 years ago
1.0.2-rc
7 years ago
1.0.1-rc
7 years ago
1.0.0-rc
7 years ago
0.0.1
7 years ago
0.0.8
7 years ago
0.0.7
7 years ago
0.0.6
7 years ago
0.0.5
7 years ago
1.0.4
7 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago