Start typing to search...

Identity

Manages authentication and authorization on the frontend of your Koji app.

Methods

.checkGrants(grants)

Checks whether the user has granted authorizations to the Koji app. Use this method to determine whether to request authorization for certain capabilities.

Parameters

Returns

Promise<Boolean>, Indicates whether the user has already granted authorization for the capabilities.

Example

const hasGrant = await Koji.identity.checkGrants(['username', 'push_notifications']);

Source: frontend/identity/index.ts#L88

.getToken()

Gets a token identifying the current user.

Returns

Promise<IdentityResult>, Identity information for the current user of the Koji app.

Example

const { token, presumedRole, presumedAttributes  } = await Koji.identity.getToken()

Source: frontend/identity/index.ts#L57

.requestGrants(grants, usageDescription)

Requests the specified authorization grants from the user for the Koji app.

Parameters

  • grants - AuthGrantCapability, List of authorization grants to request from the user.

  • usageDescription - String (Optional), Custom message to display when requesting the grant.

Returns

Promise<String>, Indicates whether authorization for the capabilities was successfully obtained from the user.

Example

const hasGrant = await Koji.identity.requestGrants(['username', 'push_notifications']);

Source: frontend/identity/index.ts#L112

Interfaces

IdentityResult

Identity information for the current user of the Koji app.

Properties

  • presumedAttributes - PresumedAttributes, Additional user attributes, which are returned if the user has granted username authorization via [[requestGrants]].

  • presumedRole - 'admin' | 'user' | 'unknown', Presumed role of the current user as the owner/creator (`admin`), not the owner (`user`), or not logged in (`unknown`). Admin actions must still be secured on the backend by resolving the user’s role.

  • token - String, Short-lived token to identify the user.

PresumedAttributes

User attributes that are determined via a client-side API call.

Properties

  • globalId - String (Optional), The user's global Koji account ID

  • profilePicture - String (Optional), Koji avatar for the user.

  • username - String (Optional), Koji username for the user.

PresumedAttributes

User attributes that are determined via a client-side API call.

Properties

  • globalId - String (Optional), The user's global Koji account ID

  • profilePicture - String (Optional), Koji avatar for the user.

  • username - String (Optional), Koji username for the user.

Type aliases

AuthGrantCapability

Capabilities that a user can grant the current Koji authorization to use.

Possible values

  • 'push_notifications'
  • 'username'
  • 'global_id'