The User Object

Introduced in oidc-spa v10.3

At your application level you typically have an object that represent the user that is currently using your application.

For example:

export type User = {
    id: string;
    username: string;
    displayName: string;
    email: string | undefined;
    avatarImgUrl: string;
    hasRole: (role: string) => boolean;
};

The iformations for costructing the desired user object can comes from different sources:

  • The Decoded ID Token

  • The Decoded Access Token (even if, in theory, the access token is supposed to be opaque for the SPA, the roles of the users are often only available in the JWT payload of the access token)

  • By querying a custom /api/user endpoind of your API with an access token as bearer.

  • By calling the standard userinfo OIDC endpoint.

  • By calling provider specific endpoints like keycloak's user profile.

oidc-spa adapters let you decide what the user should look like (by providing your own type definition for the User object) and how it should be created, by letting you implement a createUser function that is called with all the material that you might need to create the user object.

The first thing you need to do is to declare the desired shape of the app level user object and implement a function to create that user object (this should be framwork agnostic):

Last updated

Was this helpful?