I want to implement the new Auth0 Lock 10 in my React / Redux app.
I checked online, but nothing matches my question. There's a tutorial there , but it uses Popup mode instead of Redirect mode (default). The other one parses a URL that is useless in Lock 10.
Here's the thread:
- Auth0Lock gets an instance when the application starts
- When the user presses the login button, he shows the Lock widget (
lock.show() ) and sends LOGIN_REQUEST - The lock does its authentication on auth0.com (redirects from my localhost)
- Transfer back to my local host after successful login, create an Auth0Lock instance again
- I am waiting for the
lock.on('authenticated') event to send LOGIN_SUCCESS
And here are my actions /index.js code:
import Auth0Lock from 'auth0-lock' export const LOGIN_REQUEST = 'LOGIN_REQUEST' export const LOGIN_SUCCESS = 'LOGIN_SUCCESS' export const LOGIN_ERROR = 'LOGIN_ERROR' function loginRequest() { return { type: LOGIN_REQUEST } } function loginSuccess(profile) { return { type: LOGIN_SUCCESS, profile } } function loginError(error) { return { type: LOGIN_ERROR, error } } // import AuthService to deal with all the actions related to auth const lock = new Auth0Lock('secret', 'secret', { auth: { redirectUrl: 'http://localhost:3000/callback', responseType: 'token' } }) lock.on('authenticated', authResult => { console.log('Im authenticated') return dispatch => { return dispatch(loginSuccess({})) } }) lock.on('authorization_error', error => { return dispatch => dispatch(loginError(error)) }) export function login() { lock.show() return dispatch => {return dispatch(loginRequest())} }
Now, when I click on the login button, the regressing logger shows me the logical action LOGIN_REQUEST sent, I see the lock widget, I can log in, it redirects to auth0.com and then back to my localhost:3000/callback with a nice token . Everything is fine, I see the Im authenticated message in my console, but the logger registry does not show me that the LOGIN_SUCCESS action was sent.
I'm new to Redux, and I think I'm missing one thing, but I can't grab it. Thanks!
source share