akveo / ngx-admin-bundle-support

Support repository for ngx-admin backend bundles with issues tracking, instructions and code samples
58 stars 32 forks source link

NullInjectorError: No provider for NbAuthStrategy! #105

Open ychang-uei opened 3 years ago

ychang-uei commented 3 years ago

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 commented 3 years ago

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?