Version 18 of the Angular Auth OIDC Client (angular-auth-oidc-client) library adds Signal support to access the authenticated state and user data.
This makes it simpler to use authentication state and user data in Angular applications compared to the Observables' implementation.
The authenticated property wraps the isAuthenticated$ Observable with a Signal that holds the authenticated state of a user's session.
You can use this signal to check if the user is authenticated, and it returns object containing AuthenticatedResult:
To use the authenticated Signal, inject the OidcSecurityService and optionally assign the signal to a property.
Then, you can use the property in the template or within the component as a Signal, as is shown in the following example:
app.component.ts
import {OidcSecurityService} from 'angular-auth-oidc-client';
userData is the Signal implementation of the userData$ Observable.
Accessing the signal returns the UserDataResult object:
exportinterfaceUserDataResult{
userData:any;
allUserData:ConfigUserDataResult[];
}
exportinterfaceConfigUserDataResult{
configId:string;
userData:any;
}
You can use this to read the user data in your Angular application.
Just like the authenticated Signal, inject the OidcSecurityService and optionally assign the userData Signal to a property to use it in the template or within the component.
app.component.ts
import {OidcSecurityService} from 'angular-auth-oidc-client';
The authenticated and userData Signals in the angular-auth-oidc-client library make it easier to use authentication state and user data in Angular applications.
import {OidcSecurityService} from 'angular-auth-oidc-client';