Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module): warn if default strategy is not valid #365

Merged
merged 1 commit into from
May 31, 2019
Merged

fix(module): warn if default strategy is not valid #365

merged 1 commit into from
May 31, 2019

Conversation

motia
Copy link
Contributor

@motia motia commented May 31, 2019

Fixed a bug when 'no strategy defined!' is displayed when options.defaultStrategy is set.
Added a warning when the strategy specified in options.defaultStrategy is not a valid strategy.

Fixed a bug when 'no strategy defined!' is displayed when options.defaultStrategy is set.
Added a warning when the strategy specified in options.defaultStrategy is not a valid strategy.
@pi0 pi0 changed the title feat: improve defaultStrategy check warnings fix(module): warn if default strategy is not valid May 31, 2019
@pi0
Copy link
Member

pi0 commented May 31, 2019

Thanks!

@pi0 pi0 merged commit db6d3d4 into nuxt-community:dev May 31, 2019
@MathiasCiarlo
Copy link
Collaborator

MathiasCiarlo commented Jun 3, 2019

I use oauth2 and had not defined options.defaultStrategy in nuxt.config.js.
This made 'local' the default strategy without informing the user, and has been giving me a strange bug for months (see bottom for details). May I suggest we either refactor this, or at the very least update the docs? There is currently no information on the defaultStrategy option. (I'd be happy to do this 🙂)

  // Set defaultStrategy
  const strategyNames = strategies.map(x => x._name)

  if (!options.defaultStrategy) {
    if (strategyNames[0]) {
      options.defaultStrategy = strategyNames[0]
      logger.warn(`[AUTH]: No default strategy defined! Using ${options.defaultStrategy}.`)
    } else {
      logger.warn('[AUTH]: No default strategy defined!')
    }
  } else if (strategyNames.indexOf(options.defaultStrategy) === -1) {
    logger.warn(`[AUTH]: Default strategy ${options.defaultStrategy} is not defined!`)
  }
  // The above should probably be functionized for readability

The bug I experience:

Steps to reproduce:

  • Don't define auth.defaultStrategy in nuxt.config.js
  • Sign in with oauth2
  • Clear application storage
  • Sign in again

This makes nuxt auth mount with local strategy, instead of oauth2. This leads to the handleCallback hook never being called on redirect back from oauth2 login, which further stops the login from completing.

// nuxt.config.js
strategies: {
  keycloak: {
    ...
  }
}

@pi0
Copy link
Member

pi0 commented Jun 3, 2019

@MathiasCiarlo Thanks for sharing that. Sure please. Seems a safe improvement 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants