question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No provider for InjectionToken Nebular Auth Options in ngx-admin angular 5

See original GitHub issue

I have installed ngx-admin theme and want to customize my login auth component.

Below is what i have done to override the default auth component.

Followed this documentation exact as given

https://akveo.github.io/nebular/#/docs/auth/configuring-ui

Not sure if i have to keep auth.component.d and auth.module files inside the auth folder.

Inside the src/app/theme/components/auth folder i have files like:

theme

Under src\app\theme\components\auth\login\login.component.d.ts

import { Router } from '@angular/router';

import { NbAuthService } from '../../../../../../@nebular/auth/services/auth.service';
...
...

src\app\theme\components\auth\auth.component.js

UPDATE: after regsitering NdTokenSerive i get another error, why is it so complicated just to extend auth component!!!

import { NbAuthService } from '../../../../../@nebular/auth/services/auth.service';
import { NbTokenService } from '../../../../../@nebular/auth/services/token.service';

 NbAuthComponent.decorators = [
    { type: Component, args: [{
                selector: 'nb-auth',
                styles: [":host /deep/ nb-layout .layout .layout-container .content .columns nb-layout-column{padding:2.5rem}:host /deep/ nb-card{height:calc(100vh - 2 * 2.5rem)}:host /deep/ nb-card{margin:0}:host /deep/ .flex-centered{margin:auto}:host /deep/ nb-card-body{display:flex}@media (max-width: 550px){:host /deep/ /deep/ nb-layout .layout .layout-container .content .columns nb-layout-column{padding:0}:host /deep/ nb-card{border-radius:0;height:100vh}} "],
                template: "\n    <nb-layout>\n      <nb-layout-column>\n        <nb-card>\n          <nb-card-body>\n            <div class=\"flex-centered col-xl-4 col-lg-6 col-md-8 col-sm-12\">\n                         </div>\n          </nb-card-body>\n        </nb-card>\n      </nb-layout-column>\n    </nb-layout>\n  ",
                providers: [NbAuthService,NbTokenService]    //UPDATED
            },] },
];

\src\app@theme\components\auth\login\login.component.js

NbLoginComponent.decorators = [
{
  type: Component,
  args: [
    {
      selector: 'nb-login',
      template:`LOGIN123`,   //also here if i put html in seperate file, using templateUrl, i get 'unable to load login.component.html'
      
    }
  ]
}
];

src\app@theme\components\auth\login\login.component.js

import { Component, Inject } from "@angular/core";
import { Router } from "@angular/router";
import { NB_AUTH_OPTIONS_TOKEN } from "../../../../../../@nebular/auth/auth.options";
import { getDeepFromObject } from "../../../../../../@nebular/auth/helpers";
import { NbAuthService } from "../../../../../../@nebular/auth/services/auth.service";

src\app@theme\theme.module.ts

import { ModuleWithProviders, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

import { NbLoginComponent } from './components/auth/login/login.component';
import { NbAuthComponent } from './components/auth/auth.component';

const COMPONENTS = [
 NbLoginComponent,
 NbAuthComponent
];

@NgModule({
  imports: [...BASE_MODULES, ...NB_MODULES],
  exports: [...BASE_MODULES, ...NB_MODULES, ...COMPONENTS, ...PIPES],
  declarations: [...COMPONENTS, ...PIPES],
})

\src\app\app-routing.module.ts

import { NbLoginComponent } from './@theme/components/auth/login/login.component';
import { NbAuthComponent } from './@theme/components/auth/auth.component';

const routes: Routes = [
  { path: 'pages', loadChildren: 'app/pages/pages.module#PagesModule' },
  {
    path: 'auth',
    component: NbAuthComponent,
    children: [
      {
        path: '',
        component: NbLoginComponent,
      },
     {
        path: 'login',
        component: NbLoginComponent,
      }

Error trace:

ERROR Error: Uncaught (in promise): Error: StaticInjectorError[NbTokenService]: StaticInjectorError[NbTokenService]: NullInjectorError: No provider for NbTokenService! Error: StaticInjectorError[NbTokenService]: StaticInjectorError[NbTokenService]: NullInjectorError: No provider for NbTokenService! at _NullInjector.get (core.js:993) at resolveToken (core.js:1281) at tryResolveToken (core.js:1223)

Facing same issue from this github post: https://github.com/akveo/nebular/issues/37

If any1 resolved please provide complete answer!!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
abdelrhman92commented, Feb 24, 2018

I am facing the same issue here. I have copied the source code from ‘frameworks/auth’. Deleted the services and other stuff ‘as recommended in the docs’ left only the components, auth-options and token. so my imports in the new login components looks like this :

import { Component, Inject } from '@angular/core'; import { Router } from '@angular/router'; import { NB_AUTH_OPTIONS, NbAuthSocialLink } from '../../auth.options'; import { getDeepFromObject } from '@nebular/auth/helpers'; import { NbAuthService, NbAuthResult } from '@nebular/auth/services/auth.service';

and I did the rest of the steps, changed the routing to the new components but I got error this error

Error: StaticInjectorError(AppModule)[LoginComponent -> InjectionToken Nebular Auth Options]: StaticInjectorError(Platform: core)[LoginComponent -> InjectionToken Nebular Auth Options]: NullInjectorError: No provider for InjectionToken Nebular Auth Options! at _NullInjector.get (core.js:1002) at resolveToken (core.js:1300) at tryResolveToken (core.js:1242) at StaticInjector.get (core.js:1110) at resolveToken (core.js:1300) at tryResolveToken (core.js:1242) at StaticInjector.get (core.js:1110) at resolveNgModuleDep (core.js:10850) at NgModuleRef_.get (core.js:12083) at resolveDep (core.js:12573)

0reactions
AmruthaSushanthcommented, Jun 19, 2020

Customizing Auth into other folder without using @nebular/auth

ERROR Error: "Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[NbAuthService -> NbAuthService -> NbAuthService]: NullInjectorError: No provider for NbAuthService! get@http://localhost:4200/vendor.js:36037:27 get@http://localhost:4200/vendor.js:50031:33 get@http://localhost:4200/vendor.js:50031:33 get@http://localhost:4200/vendor.js:50031:33 get@http://localhost:4200/vendor.js:67332:33 get@http://localhost:4200/vendor.js:65066:35

I have also this error… I put NbAuthModule.forRoot({ strategies: [ NbPasswordAuthStrategy.setup({ name: ‘email’, }), ], forms: {}, }),

inside app.module.ts But I got another error

ERROR in ./src/app/app.module.ts like Module not found: Error: Can’t resolve ‘./framework/auth/auth.module’ in ‘/home/amrutha/Documents/assignment/ngx-admin-starter-kit/src/app’ ERROR in ./src/app/app.module.ts Module not found: Error: Can’t resolve ‘./framework/auth/public_api’ in ‘/home/amrutha/Documents/assignment/ngx-admin-starter-kit/src/app’… Anyone please help me for solve this issue for customizing the ngx-admin Auth

Read more comments on GitHub >

github_iconTop Results From Across the Web

NG0201: No provider for {token} found! - Angular
A provider is a mapping that supplies a value that you can inject into the constructor of a class in your application. Read...
Read more >
Custom Auth Components - Nebular - GitHub Pages
Customizable Angular UI Library based on Eva Design System with 40+ UI components, 4 visual themes, Auth and Security modules.
Read more >
Angular InjectionToken throws 'No provider for InjectionToken'
After asking on the official angular repository, it turns out to be a simple solution. Instead of passing the service name as a...
Read more >
NullInjectorError: No provider for InjectionToken ToastConfig!
angular #angulartutorial #angularproject #errorUncaught (in promise): NullInjectorError: No provider for InjectionToken ToastConfig!
Read more >
Customize ngx-admin login page - Google Groups
At this moment i show in /node_modules/@nebular/auth/components/login/login.component.js . There is no login.component.ts. Inside the .js you can see the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found