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

NullInjectorError: No provider for NbAuthStrategy! #105

Open
ychang-uei opened this issue May 18, 2021 · 1 comment
Open

NullInjectorError: No provider for NbAuthStrategy! #105

ychang-uei opened this issue May 18, 2021 · 1 comment

Comments

@ychang-uei
Copy link

ychang-uei commented May 18, 2021

I'm trying to set up a demo from ngx-admin Angular Frontend by following the instructions with the following code:

/*
 * Copyright (c) Akveo 2019. All Rights Reserved.
 * Licensed under the Single Application / Multi Application License.
 * See LICENSE_SINGLE_APP / LICENSE_MULTI_APP in the 'docs' folder for license information on type of purchased license.
 */
import { Component, OnInit } from '@angular/core';
import { NbAuthStrategy, NbAuthToken, NbTokenStorage } from '@nebular/auth';
import { environment } from '../environments/environment';
import { AnalyticsService } from './@core/utils';

@Component({
  selector: 'ngx-app',
  template: '<router-outlet></router-outlet>',
})
export class AppComponent implements OnInit {
  constructor(private analytics: AnalyticsService,
              private authStrategy: NbAuthStrategy,
              private tokenStorage: NbTokenStorage) {
    // this.initTestUserToken();
  }

  ngOnInit(): void {
    this.analytics.trackPageViews();
  }

  initTestUserToken() {
    const demoTokenInitKey = 'demo_token_initialized';
    const demoTokenWasInitialized = localStorage.getItem(demoTokenInitKey);
    const currentToken = this.tokenStorage.get();
    if (!demoTokenWasInitialized && !currentToken.isValid()) {
      // local storage is clear, let's setup demo user token for better demo experience
      this.tokenStorage.set(this.authStrategy.createToken<NbAuthToken>(environment.testUser.token));
      localStorage.setItem(demoTokenInitKey, 'true');
    }
  }
}

However, l've been getting this error when running it locally:

image

Is there anything I'm missing from the code?

@ychang-uei
Copy link
Author

ychang-uei commented May 18, 2021

Okay, i now figured out i was able to get past the error by adding the following code from auth.module.ts:

  providers: [
    ...
    {
      provide: NbAuthStrategy, useClass: NbAuthStrategyOptions
    },
   ....
  ],

However, I cannot by pass the login page:

image

How can I bypass this login page?

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

No branches or pull requests

1 participant