Start typing to search...

Identity

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

Constructor

Instantiates the Identity class.

Parameters

Example

const identity = new KojiBackend.Identity({ res });

Methods

.pushNotificationToOwner(notification)

Sends a notification to the owner of the Koji app.

Parameters

  • notification - PushNotification, Defines a notification to send to a user. Use [[pushNotificationToOwner]] to send notifications to the owner of the Koji app. Use [[pushNotificationToUser]] to send notifications to any user who interacts with the Koji app and has granted the appropriate authorization.

Returns

Promise<Void>

Example

await identity.pushNotificationToOwner({
 icon: '❓',
 appName: 'Ask me anything',
 message: 'Someone asked you a question! Respond now',
 ref: '?dynamic-receipt=seller',
});

Source: backend/identity/index.ts#L130

.pushNotificationToUser(userId, notification)

Sends a notification to the user who interacted with the Koji app.

Parameters

  • userId - String, User’s unique ID for this Koji. To get the user's ID, see [[resolveUserFromToken]].

  • notification - PushNotification, Defines a notification to send to a user. Use [[pushNotificationToOwner]] to send notifications to the owner of the Koji app. Use [[pushNotificationToUser]] to send notifications to any user who interacts with the Koji app and has granted the appropriate authorization.

Returns

Promise<Void>

Example

const user = identity.resolveUserFromToken(userToken);

await identity.pushNotificationToUser(user.id, {
 icon: '❓',
 appName: 'Ask me anything',
 message: 'Your custom video is ready! View now',
 ref: '?dynamic-receipt=buyer',
});

Source: backend/identity/index.ts#L101

.resolveUserFromToken(token)

Gets the user’s information for this Koji.

Parameters

  • token - String, Short-lived token identifying the current user, which is generated with the frontend identity module. See [[getToken]].

Returns

Promise<User>, Object containing information about the user.

Example

// Get the user token (generated using the frontend identity module)
const userToken = req.headers.authorization;

const user = await identity.resolveUserFromToken(userToken);

Source: backend/identity/index.ts#L158

Interfaces

BackendConfigurationInput

Configuration information for the Koji app.

Properties

  • projectId - String (Optional), Unique identifier for the Koji app. Will override data passed through `res`.

  • projectToken - String (Optional), Secret key for the Koji app. Will override data passed through `res`.

  • res - Response (Optional), Express response object. Used in conjunction with middleware to scope environment variables for customized versions of the original Koji app. For the original definition see [[https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/express/index.d.ts#L127 | @types/express]].

PushNotification

Defines a notification to send to a user. Use [[pushNotificationToOwner]] to send notifications to the owner of the Koji app. Use [[pushNotificationToUser]] to send notifications to any user who interacts with the Koji app and has granted the appropriate authorization.

Properties

  • appName - String, Headline for the message. For example, the name of the Koji app that generated the notification.

  • icon - String, Icon to display next to the message, either the URL of an image or an emoji character.

  • message - String, Content of the message.

  • ref - String (Optional), Query parameters to append to the Koji app's URL when the notification is tapped. For example, load the admin experience or a dynamic receipt from the notification.

User

Information about a user of the Koji app. To retrieve a user's information, use [[resolveUserFromToken]].

Properties

  • attributes - [index: string]: any | null, Object containing custom information about the user.

  • dateCreated - String, Date the user's information was created or updated on this Koji.

  • grants - UserGrants, Object containing information about capabilities that the user has authorized this Koji to use.

  • id - String, User’s unique ID for this Koji.

  • role - null | 'admin' | 'user' | 'unknown', User’s role for this Koji – the owner/creator (`admin`), not the owner (`user`), or not logged in (`unknown`).

UserGrants

Object containing information about capabilities that the user has authorized this Koji to use.

Properties

  • pushNotificationsEnabled - Boolean, Whether the user has granted push notification access.

UserGrants

Object containing information about capabilities that the user has authorized this Koji to use.

Properties

  • pushNotificationsEnabled - Boolean, Whether the user has granted push notification access.