Aungluar 新手進行身份驗證。我將 auth0-angular 包下載到我的專案中,現在我在創建 WebAuth() 實體時遇到此錯誤(IDE:VS Code):
" 型別 'typeof import("c:/Users/Owner/Desktop/coding_course_docs/AngularAudioPlayer/node_modules/@auth0/auth0-angular/auth0-auth0-angular")' 上不存在屬性 'WebAuth'"
這是我的代碼:
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';
關于我做錯了什么的任何想法?
uj5u.com熱心網友回復:
您是否嘗試過為 auth0 使用另一個匯入?
import * as auth0 from "auth0-js";
請注意,使用它需要以下依賴項:auth0-js, not @types/auth0-js(也應該添加,但它只是添加,以便您在 TypeScript 中獲得更好的 auth0 型別)
如果要使用auth0-angular,則應切換到另一種匯入型別:import { AuthService } from '@auth0/auth0-angular';。您可以在此處找到有關使用此 AuthService 的更多詳細資訊:https ://auth0.com/docs/libraries/auth0-angular-spa
雖然第一個應該解決您的問題,但從長遠來看,第二個可能是更好的方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/320951.html
上一篇:使用角度排氣貼圖防止多次提交
下一篇:角度排氣圖
