Skip to main content

User authentication

After creating your users, you will need to authenticate them with the server.

You can do this with a combination of the username and password authentication method, and the get user APIs.

To set up authentication with the default database, we will pass a verifyPassword function to the server, and use the database APIs to verify our user.


import CollabServer from '@pdftron/collab-server'
import CollabDatabase from '@pdftron/collab-db-postgresql';
const db = new CollabDatabase({
await db.connectDB();
const resolvers = db.getResolvers();
const server = new CollabServer({
verifyPassword: async (username, password) => {
const user = await db.getUserByUsername(username);
if(!user) {
return false; // username is invalid / user not found
// remember that the password in the DB is hashed!
const hashedPassword = user.password;
// validate the password with your own logic
const passwordIsValid = validatePassword(hashedPassword);
return passwordIsValid