使用auth0为angular 2创建用户配置文件系统?

使用auth0为angular 2创建用户配置文件系统?,angular,authentication,auth0,Angular,Authentication,Auth0,因此,我一直在关注auth0网站上关于如何为我的应用程序构建用户配置文件系统的教程,但我无法让它完全正常工作。我的登录工作正常,但当将数据拉入用户配置文件时,它就不想工作了。不知道从这里到哪里去 我正在使用的教程 我的代码目前是 profile.components.html <div class="panel panel-default profile-area"> <div class="panel-heading"> <h3>Pr

因此,我一直在关注auth0网站上关于如何为我的应用程序构建用户配置文件系统的教程,但我无法让它完全正常工作。我的登录工作正常,但当将数据拉入用户配置文件时,它就不想工作了。不知道从这里到哪里去

我正在使用的教程

我的代码目前是

profile.components.html

<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

    // services/auth.service.ts
import { Injectable,  NgZone } from '@angular/core';
import {Router} from '@angular/router';
import { tokenNotExpired } from 'angular2-jwt';


// We want to avoid any 'name not found'
// warnings from TypeScript
declare var Auth0Lock: any;

@Injectable()
export class AuthenticationService {
    constructor( private _router: Router, private _zone: NgZone) {}

    lock = new Auth0Lock('gpnhOqi20kE7pOM61DYI6BuI93ZjgA4j', 'jasont8.auth0.com');

    login() {
        this.lock.show((error: string, profile: Object, id_token: string) => {
            if (error) {
                console.log(error);
            }
            // We get a profile object for the user from Auth0
            localStorage.setItem('profile', JSON.stringify(profile));
            // We also get the user's JWT
            localStorage.setItem('id_token', id_token);
        });
    }

    logout() {
        // To log out, we just need to remove
        // the user's profile and token
        localStorage.removeItem('profile');
        localStorage.removeItem('id_token');
    }

    loggedIn() {
        return tokenNotExpired();
    }
}

你可能想试试这个

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