2017-04-04 1 views
5

사용자 정의 Propertise :Angular2 중포 기지 설정 사용자 나 사용자 지정 속성을 설정하려고 또는 속성 <code>auth.updateProfile</code> 방법을 사용하지만, 그것은 그 <a href="https://firebase.google.com/docs/auth/web/manage-users#update_a_users_profile" rel="noreferrer">docs</a>에서 언급 있기 때문에 그것은 단지 <code>displayName</code> 속성을 저장했습니다

this.af.auth.createUser({ 
    email: formData.value.email, 
    password: formData.value.password, 
}).then((user) => { 
    let userProfile = formData.value; 
    userProfile.role = AuthService.ROLE_PATIENT; 
    userProfile.displayName = `${formData.value.firstName} ${formData.value.lastName}`; 
    user.auth.updateProfile(userProfile).then(function(){ 
    this.router.navigate(['/']); 
}); 

이제 문제는 어떻게 설정할 수 있습니다 내가 그들을 얻을 수 있도록 사용자의 사용자 속성 FirebaseAuthState

질문 : 각 사용자마다 사용자 정의 속성을 저장해야하는 이유는 무엇입니까?

답변 : 내가 데이터베이스 예에 저장됩니다 role 속성을 사용하여 특정 경로를 활성화 Auth Guard 함께 일하고 있어요 때문에 :

canActivate(route: ActivatedRouteSnapshot, 
       state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { 
    //Currently I'm using this which only check that user is logged in or not 
    return this.auth 
     .take(1) 
     .map((authState: FirebaseAuthState) => !!authState) 
     .do(authenticated => { 
     if (!authenticated) this.router.navigate(['/login']); 
     }); 
    } 

을하지만 사용자를 확인하기 위해 한 번 더 검사를 원하는의 역할을 예 : 위의 사용자를 생성하는 동안 저장 한 환자 : return user.role == 'patient'

+0

Firebase 콘솔과 Google Cloud 콘솔은 동일한 기본 역할과 권한을 사용합니다. 상위 레벨에서는 소유자, 편집자 및 뷰어입니다. 내 문제를 해결하지 못할 –

+0

, 역할에 맞는 솔루션이나 이론을 가질 수 있습니까? –

+0

do에서 그들을 결합 할 수 없습니까? – Chrillewoodz

답변

1

Firebase 인증의 기존 ID 공급자는 사용자 지정 속성을 추가 할 수 없습니다. 사용자 지정 속성을 추가하려면 사용자 지정 식별 공급자 (minting custom tokens in a trusted processsigning in with a custom token 참조)를 구현하거나 client-side look-up of the additional information from an alternate data source (예 : Firebase 데이터베이스)을 구현해야합니다. 그건 상당히 억지하지만 그냥 작동 할 수

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { 
    //Currently I'm using this which only check that user is logged in or not 
    return this.auth 
     .take(1) 
     .map((authState: FirebaseAuthState) => { 

     return this.af.database.list('/path/to/account').first().map((account: IAccount) => { 

      if (authState && account.role === 'patient') { 
      return true; 
      } 
      else { 
      return this.router.navigate(['/login']); 
      } 
     }); 
     }); 
    } 

:

0

아마도 당신은 이런 식으로 뭔가를 할 수 있습니다. 또는 답을 찾기 위해 길을 따라 도울 수 있습니다.