hi!
i'm using metronic angular with ionic. I connected to my wep abi login page.I works fine. I wanted to take loggend user's id or token etc. on a page. could you write me a simple expample code.
I wrote like this
ngOnInit(): void {
this.bindTickets();
this.user$ = this.auth.currentUserSubject.asObservable();
}
when i console.log i can see all data but I couldn't parse (or something)
thank you
You're welcome! I'm glad to hear that it worked for you. If you have any more questions or need further assistance with your code or any other topic, feel free to ask.
thank you
It worked, just same writing
ngOnInit(): void {
this.bindTickets();
this.user$ = this.auth.currentUserSubject.asObservable();
this.user$.subscribe((user) => {
if (user) {
const userId = user.Id; //
console.log("User ID:", userId);
}
});
}
You can access the user's ID by subscribing to this.user$ and extracting the necessary information.
Here's a basic example of how you can do it:
import { Component, OnInit } from "@angular/core";
import { AuthService } from "path-to-your-auth-service"; // Replace with your actual import path
@Component({
selector: "app-your-component",
templateUrl: "your-component.component.html",
})
export class YourComponent implements OnInit {
user$;
constructor(private auth: AuthService) {}
ngOnInit(): void {
// Assuming currentUserSubject contains user data
this.user$ = this.auth.currentUserSubject.asObservable();
// Subscribe to user$ to access user data
this.user$.subscribe((user) => {
if (user) {
// Access user properties like ID or token
const userId = user.id; // Replace "id" with the actual property name
console.log("User ID:", userId);
}
});
}
}