Auth0.js: how to pass initialScreen to the hosted login page using authorize callback?

Created on 14 Jan 2017  路  25Comments  路  Source: auth0/auth0.js

Just trying to send my users to either "log in" or "sign up" through the hosted login page.

Inspecting the config object passed to the hosted login page with a console log shows that initialScreen seems to be getting stripped if I provide it as an option to the authorize call on a WebAuth object.

Most helpful comment

@tonyneel923 @devpascoe @thedavidmeister Actually, just fixed this:

Using auth.js:

this.auth0.authorize({
      initialScreen: 'signUp' // or login
});

Then within your hosted page, you can use this:

initialScreen: config.extraParams.initial_screen,
var lock = new Auth0Lock(config.clientID, config.auth0Domain, {
    ...,
    ...,
    initialScreen: config.extraParams.initial_screen,
}

All 25 comments

@thedavidmeister it should be fixed in the latest auth0.js version

Nope 馃槶 not for me

this.auth0.authorize({
        redirectUri: location.origin + '/callback',
        connection: process.env.AUTH_DB,
        initialScreen: 'signUp'
})

Any news on this?

@hzalaz Can this issue be reopened? Still doesn't seem to be configurable for me.

@tonyneel923 @devpascoe @thedavidmeister Actually, just fixed this:

Using auth.js:

this.auth0.authorize({
      initialScreen: 'signUp' // or login
});

Then within your hosted page, you can use this:

initialScreen: config.extraParams.initial_screen,
var lock = new Auth0Lock(config.clientID, config.auth0Domain, {
    ...,
    ...,
    initialScreen: config.extraParams.initial_screen,
}

thanks @maxtuzz. Is there something we can do to better document this?

Documentation about how extra parameters work and are passed to lock would go a long way. Maybe using this as an example on how you can modify how lock behaves on a per-client basis.

For instance, to find out how our additional params were actually being delivered and served on lock I had to modify it to console out the contents of extra params.

Alright. I'll ping our docs team with this info! Thanks for your help and understanding! 馃帀

@luisrudge @hzalaz Would it be reasonable to create a generic way to pass extra params in the authorize URL? That way each option wouldn't need to be added specifically.

@brandonarbini you mean specifying unknown params in the .authorize method?

@luisrudge Yeah, I want to be able to customize the hosted login page based on extraParams (as they're called in the default hosted login page HTML) passed to the page, but there doesn't seem to be a way to add more params to the authorize call. I think that's where it would be added at least. (Sorry, I'm pretty new to Auth0).

the authorize call shouldn't be removing the extra params. See here and here. It should just emit a warning (that you can disable).

The oauth/token call is actually cleaned up, as you can see here. What is the behavior that you're getting?

@luisrudge Thanks so much for pointing me in the right direction. I updated to the latest auth0.js and tried again and it's working as expected. I'm not sure if it was the update or the way I was calling .authorize(), but it's doing its thing. 馃挴

uhuuuul 馃帀

so I did what you said @maxtuzz and then Im able to use a custom page, but I dont understand how to send the users login-credentials to auth0 and get logged in, is it possible to get some guidance pls?

Hi @AndreaRylander, seems like you need some guidance on how to use the SDK. Please reach out to our amazing support team at https://support.auth0.com so they can better assist you with your scenario.

@maxtuzz is that work around still working? I can console.log the extra params in hosted page and see that the param is arriving ok but then setting initialScreen from there doesnt seem to do anything, hosted UI still loads login screen.

and how do i silence the warning in the console in auth.js about the extra param for initialScreen @luisrudge ?

So my hosted page was referencing lock v9 :/

but yes still would be good to silence the warning in js console for my custom param

@devpascoe It is still working for me, yes. Make sure you are setting initialScreen to extraParams.initial_screen. It's important that the extra params are underscore separated and the assignment string is lower camel-case.

Is there any reason this isn't provided as an option by default? It seems like a super common use case that I would have expected to be available out of the box. Forcing editing of a custom hosted page means that all our devs will have to update this on their dev accounts in order to get this functionality to work and cause confusion about it not working properly.

For the people that end up here, the authorize() call supports a mode parameter:

const auth = new auth0.WebAuth({
  clientID: '...',
  domain: '...'
});

// Show the sign-up screen
auth.authorize({ mode: 'signUp' });

Anyone managed to directly navigate to the sign up page (Universal Login) using the auth. authorize function ?

I tried both:
1) auth.authorize({ mode: 'signUp' });
2) auth.authorize({ initialScreen: 'signUp' });

and doesn't seem to work.

Can confirm, it would appear that auth.authorize({ mode: 'signUp' }); no longer works

Was this page helpful?
0 / 5 - 0 ratings