Giter Club home page Giter Club logo

Comments (4)

mauriciovigolo avatar mauriciovigolo commented on September 4, 2024 3

Hi @czeckd, how are you?

First of all, sorry for the lack of response. Was travelling the past two weeks and didn't have time to watch the issues.
So, about your issue, what about using the user profile? The keycloak-js give us a function to get the user details. Currently the KeycloakProfile has the following attributes:

interface KeycloakProfile {
  id?: string;
  username?: string;
  email?: string;
  firstName?: string;
  lastName?: string;
  enabled?: boolean;
  emailVerified?: boolean;
  totp?: boolean;
  createdTimestamp?: number;
}

Just included in the header of the example keycloak-heroes at the user area, the name and email from the user. Take a look at the app.component.html and app.component.ts.

  • app.component.html
<clr-dropdown-menu *clrIfOpen clrPosition="bottom-right">
    <div class="userDetails" *ngIf="userDetails">
        <h2>{{userDetails.firstName}}</h2>
        <p>
            {{userDetails.email}}
        </p>
    </div>
    <a href="#" clrDropdownItem>Log out</a>
</clr-dropdown-menu>
  • app.component.ts
import { Component, OnInit } from '@angular/core';
import { KeycloakProfile } from 'keycloak-js';
import { KeycloakService } from 'keycloak-angular';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  userDetails: KeycloakProfile;

  constructor(private keycloakService: KeycloakService) {}

  async ngOnInit() {
    this.userDetails = await this.keycloakService.loadUserProfile();
  }
}

Let me know if this helps you, otherwise lets talk and think about solutions.

Thanks!

from keycloak-angular.

czeckd avatar czeckd commented on September 4, 2024 1

This will work perfectly! Thank you so much!

from keycloak-angular.

jinojohn avatar jinojohn commented on September 4, 2024

Worked for me too.!! Thanks a lot

from keycloak-angular.

andreivictor avatar andreivictor commented on September 4, 2024

I've noticed that loadUserProfile() generates a HTTP request (url: `../account).

So if you are obsessed in reducing HTTP Requests, I suggest to use this method only if you can't find the proper information in the tokenParsed property.

from keycloak-angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.