Auth0 Home Blog Docs

Pass initialScreen to Universal Login with Express/passport-auth0

Hello,

I direct users to Universal Login in my Express app with the standard /login and /callback routes. I’m now trying to create a /signup route that will go directly to the Sign Up tab on the Universal Login page.

From some other forum posts (here and here) it looks like this is possible using webAuth or a custom signup, but I haven’t been able to find any documentation of this being possible with Express, hoping to get some help on this (or confirmation it’s not currently possible?).

In my mind the routes would be differentiated like this:

router.get('/login', passport.authenticate('auth0', {
  scope: 'openid email profile',
  mode: 'login',
}), function (req, res) {
  res.redirect('/');
});

router.get('/signup', passport.authenticate('auth0', {
  scope: 'openid email profile',
  mode: 'signUp',
}), function (req, res) {
  res.redirect('/');
});

…with the Universal Login page getting initialScreen: config.extraParams.mode, added to options.

However that’s not working. I also tried changing the value of initialScreen in the Passport authentication strategy but doesn’t seem I can affect settings there either. The only way I’ve been able to change it has been by customizing the Universal Login page, but then it always goes to sign up so isn’t really the solution.

Appreciate any advice on this! Thanks in advance.

Hi,
After several attempts I found out that the way to send extraParams is by overriding the strategy:

const authorizationParams = Auth0Strategy.prototype.authorizationParams;
Auth0Strategy.prototype.authorizationParams = function(options) {
    let params = authorizationParams(options);
    if (options && options.mode) {
          params.mode = options.mode;
    }
    return params;
};

const strategy = new Auth0Strategy({...});
passport.use(strategy);
1 Like

Thanks a lot for sharing that knowledge with the rest of community!

Hi, It’s not working. should I set up more?

@ken3 can you provide more details or your code?

In hosted Auth0 Login Page

initialScreen: config.extraParams.mode

router.get(
‘/login’,
passport.authenticate(‘auth0’, {
scope: ‘openid email profile’,
initialScreen: ‘login’,
}),
(req, res) => res.redirect(’/’),
)
router.get(
‘/signup’,
passport.authenticate(‘auth0’, {
scope: ‘openid email profile’,
initialScreen: ‘signUp’,
}),
(req, res) => res.redirect(’/’),
)

this is my codes and I create new pull request.

@ofer-papaya I’m using universal login with express app

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