Aungluar newbie working on authentication. I downloaded the auth0-angular package to my project, and now I'm getting this error for my WebAuth() instance creation (IDE: VS Code):
" Property 'WebAuth' does not exist on type 'typeof import("c:/Users/Owner/Desktop/coding_course_docs/AngularAudioPlayer/node_modules/@auth0/auth0-angular/auth0-auth0-angular")' "
Here's my code:
import { Injectable } from '@angular/core';
import * as auth0 from '@auth0/auth0-angular';
import { environment } from '../../environments/environment';
import{
Observable,
BehaviorSubject,
bindNodeCallback,
of
} from 'rxjs';
import { Router } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class AuthService {
//instance of auth0-WebAuth that is used for authentication
auth0 = new auth0.WebAuth({
clientID: environment.auth0.clientID,
domain: environment.auth0.domain,
responseType: 'token id_token',
scope: 'openid profile email'
});
//'localStorage' keys (for storing authentication and user profile data) that track whether or not to renew token
private _authFlag = 'isLoggedIn';
private _userProfileFlag = 'userProfile';
Any ideas of what I did wrong?
CodePudding user response:
Have you tried to use another import for auth0?
import * as auth0 from "auth0-js";
Please note that the following dependency is required to use it: auth0-js
, not @types/auth0-js
(which should be added as well but it's just addition so you get better types in TypeScript for auth0)
If you want to use auth0-angular
, then you should switch to another import type: import { AuthService } from '@auth0/auth0-angular';
. You can find more details on usage of this AuthService here: https://auth0.com/docs/libraries/auth0-angular-spa
While the first one should fix your issue, the second one is probably better way to go in the long run.