const identity = new KojiBackend.Identity({ res });
Manages authentication and authorization on the backend of your Koji app.
Instantiates the Identity class.
config
- BackendConfigurationInput, Configuration information for the Koji app.
const identity = new KojiBackend.Identity({ res });
Sends a notification to the owner of the Koji app.
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.
Promise<Void>
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
Sends a notification to the user who interacted with the Koji app.
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.
Promise<Void>
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
Gets the user’s information for this Koji.
token
- String, Short-lived token identifying the current user, which is generated with the frontend identity module. See [[getToken]].
Promise<User>, Object containing information about the user.
// 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
Configuration information for the Koji app.
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]].
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.
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.
Information about a user of the Koji app. To retrieve a user's information, use [[resolveUserFromToken]].
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`).
Object containing information about capabilities that the user has authorized this Koji to use.
pushNotificationsEnabled
- Boolean, Whether the user has granted push notification access.
Object containing information about capabilities that the user has authorized this Koji to use.
pushNotificationsEnabled
- Boolean, Whether the user has granted push notification access.