Auth0 Home Blog Docs

Passing initialScreen to Lock from auth0-spa-js

I’m trying to accomplish what the question linked below is doing, but from the auth-spa-js framework.

Customizing the universal login widget is straightforward, but when I try to use it from loginWithRedirect(), I can’t figure out how to send a custom parameter the way that you can with WebAuth (by passing { mode: ‘signUp’ | ‘login’ } as an option).

Is there a way to accomplish this?

Thanks!

Turns out it was super easy - I can pass any extra parameters to loginWithRedirect and they will end up on the authorize URL string as url-encoded parameters.

loginWithRedirect({ mode: 'signUp' });

…and in the custom login page:

// retrieve screen mode from extra params if sent; default to 'login'
var mode = config.extraParams.mode || 'login';
...
var lock = new Auth0Lock(config.clientID, config.auth0Domain, {
  auth: {
 // ...
  },
  // add a selector for which screen to put up 
  initialScreen: mode,
});

I had a logic error in my first attempt :wink:

Thanks a lot for sharing it with the rest of community!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.