Skip to main content

User management

If you want to use the default database to manage your users, we provide some utility APIs to help achieve this. If you need any flexibility beyond what we provide, you should consider setting up your own database for user management.

Creating users#

note

Please note that this is an API for creating users in your database with a username and password. If you have your own user database set up, you should not use these apis.

If you are looking to create an anonymous user, please follow this guide.

To create a user, use the createUser API.

createUser(user): Promise<DatabaseUser>#

  • user (object) information about the user to create
    • email (string) the users email
    • password (string) the users hashed password. Do not store plain text passwords!
    • userName (string) the users username. Optional.

Returns a DatabaseUser entity..

To use this API its recommended to set up your own endpoint (probably using express).

Example

import CollabDatabase from '@pdftron/collab-db-postgresql';
import express from 'express';
const db = new CollabDatabase({
...params
})
await db.connectDB();
const app = express();
app.post('/sign-up', async (req, res) => {
const { userName, email, password } = req.body;
// Make sure to hash your password!
const hashedPassword = hashPassword(password)
const user = await db.createUser({
userName,
email,
password: hashedPassword
})
return res.status(200).send({
id: user.id
})
})
app.listen(3000)

Getting users#

There are three ways to get user data, documented below.

getUser(id): Promise<DatabaseUser>#

  • id (string) the users id

Gets a user by their ID.

Resolves with a DatabaseUser entity.

getUserByEmail(email): Promise<DatabaseUser>#

  • email (string) the email of the user

Gets a user by their email.

Resolves with a DatabaseUser entity.

getUserByUsername(username): Promise<DatabaseUser>#

  • username (string) the username of the user

Gets a user by their username.

Resolves with a DatabaseUser entity.

Editing users#

You can use the following APIs to edit and disable a user.

editUser(user): Promise<DatabaseUser>#

  • user (DatabaseUser) the information to edit. Only id is required to identify the user you want to edit, all other fields are optional. Only fields you pass in will be updated.

Resolves with the updated DatabaseUser

deactivateUser(id): Promise<DatabaseUser>#

  • id (string) the Id of the user to deactivate

Sets a users status to INACTIVE

Resolvers with the updated DatabaseUser entity.

Database entities#

DatabaseUser#

A database user entity is an object with the following shape. Properties with a ? are optional (but recommended).

{
id: string;
userName?: string;
type?: 'STANDARD' | 'ANONYMOUS';
email: string;
password?: string;
status?: "ACTIVE" | "INACTIVE";
createdAt?: number (timestamp in ms);
updatedAt?: number (timestamp in ms);
}