使用auth0为角度2制作用户配置文件系统?

时间:2017-07-17 23:29:33

标签: angular authentication auth0

所以我一直在auth0网站上关于如何为我的应用程序构建用户配置文件系统的教程,但我无法让它完全正常工作。我已经达到了我的登录工作正常的程度,但是当将数据提取到用户配置文件中时,它只是不想工作。不知道从哪里去。

使用https://auth0.com/docs/quickstart/spa/angular2/02-user-profile

的教程

我的代码目前是

profile.components.html

rawEnvironmentFromLocalStore()

profile.components.ts

<div class="panel panel-default profile-area">
    <div class="panel-heading">
        <h3>Profile</h3>
    </div>
    <div class="panel-body">
        <img src="{{profile?.picture}}" class="avatar" alt="avatar">
        <div>
            <label><i class="glyphicon glyphicon-user"></i> Nickname</label>
            <h3 class="nickname">{{ profile?.nickname }}</h3>
        </div>
        <pre class="full-profile">{{ profile | json }}</pre>
    </div>
</div>

authentication.service.ts

import { Component, OnInit } from '@angular/core';
import { AuthenticationService  } from './../services/authentication.service';


interface User {
    id: number,
    name: string,
    image: string
}

@Component({
    selector: 'db-profile',
    templateUrl: 'app/profile/profile.component.html'
})
export class ProfileComponent  implements OnInit {

    profile: any;

    constructor(public auth: AuthenticationService) { }

    ngOnInit() {
        if (this.auth.userProfile) {
            this.profile = this.auth.userProfile;
        } else {
            this.auth.getProfile((err, profile) => {
                this.profile = profile;
            });
        }
    }

}

1 个答案:

答案 0 :(得分:0)

您可能想尝试这个

constructor(private auth: Auth) {
    this.profile = JSON.parse(localStorage.getItem('profile'));
    this.token = localStorage.getItem('id_token');
    console.log(this.profile);    
}