Integrate Auth0 with Tiger Data
Use Tiger Cloud or self-hosted TimescaleDB as the user store for an Auth0 custom database connection.
Auth0 is an identity platform that provides authentication and authorization as a service. With a custom database connection, Auth0 authenticates users against a database you own instead of storing them in Auth0.
This page shows you how to use Tiger Data as the user store for an Auth0 custom database connection, so that your users live in your service or database while Auth0 handles the login flow.
Auth0 runs custom database action scripts from its own infrastructure, so it must reach your service or database over the network. For Tiger Cloud, allowlist Auth0's IP addresses for your region. A self-hosted TimescaleDB instance must be reachable from Auth0, either directly or through a tunnel. Never expose a database to the internet without appropriate firewalling and encryption.
In this integration guide, you:
- Create the users table in your service or database.
- Configure an Auth0 custom database connection with action scripts.
- Verify that Auth0 reads and writes users in your service or database.
Prerequisites for this integration guide
To follow these steps, you'll need:
- A Tiger Cloud service, or a running instance of self-hosted TimescaleDB.
- Your connection details.
- An Auth0 account with access to a tenant.
Create the users schema in your service or database
Section titled “Create the users schema in your service or database”Auth0's PostgreSQL action scripts hash passwords with bcrypt and read and write a users table. Create that table before you configure the connection.
- Connect to your service or database
Connect to your service or database with your connection details.
- Create the users table
Run the following SQL, adapted from Auth0's reference schema:
CREATE TABLE users (id SERIAL PRIMARY KEY,email VARCHAR(255) NOT NULL UNIQUE,password VARCHAR(255) NOT NULL,nickname VARCHAR(255),email_verified BOOLEAN);The
passwordcolumn stores a bcrypt hash, which the action scripts compute. Tiger Data never sees plaintext passwords.
Configure the custom database connection in Auth0
Section titled “Configure the custom database connection in Auth0”Create a database connection in Auth0, store your connection details, and add the action scripts that read and write your users table.
- Create a database connection
In the Auth0 Dashboard, go to
Authentication>Database, then clickCreate DB Connection. Give the connection a name and create it. - Enable your own database
Open the connection, select the
Custom Databasetab, and turn onUse my own database. TheDatabase Action Scriptseditor appears. - Store your connection string
In the Settings section below the script editor, add a parameter for your connection details, for example
DATABASE_CONNECTION_STRING, with a value like:postgres://<user>:<password>@<host>:<port>/<dbname>?sslmode=requireThe action scripts read this value from the
configurationobject, so your credentials stay out of the script body. Tiger Cloud requires an encrypted connection, so keepsslmode=require. - Add the Login script
Select the
Loginscript, choose thePostgreSQLtemplate, and adapt it to read your connection string fromconfiguration:function login(email, password, callback) {const bcrypt = require('bcrypt');const postgres = require('pg');const conString = configuration.DATABASE_CONNECTION_STRING;postgres.connect(conString, function (err, client, done) {if (err) return callback(err);const query = 'SELECT id, nickname, email, password FROM users WHERE email = $1';client.query(query, [email], function (err, result) {done();if (err || result.rows.length === 0) {return callback(err || new WrongUsernameOrPasswordError(email));}const user = result.rows[0];bcrypt.compare(password, user.password, function (err, isValid) {if (err || !isValid) {return callback(err || new WrongUsernameOrPasswordError(email));}return callback(null, {user_id: user.id,nickname: user.nickname,email: user.email,});});});});} - Add the Create and Get User scripts
Add the
Createscript so Auth0 can register new users, hashing the password with bcrypt before insert:function create(user, callback) {const bcrypt = require('bcrypt');const postgres = require('pg');const conString = configuration.DATABASE_CONNECTION_STRING;postgres.connect(conString, function (err, client, done) {if (err) return callback(err);bcrypt.hash(user.password, 10, function (err, hashedPassword) {if (err) return callback(err);const query = 'INSERT INTO users(email, password) VALUES ($1, $2)';client.query(query, [user.email, hashedPassword], function (err) {done();return callback(err);});});});}Add the
Get Userscript the same way, reading fromconfiguration.DATABASE_CONNECTION_STRING. - Add the Verify, Change Password, and Delete scripts
Add the scripts for the operations you want Auth0 to perform in your service or database. Each one starts from the
PostgreSQLtemplate and reads the connection string fromconfiguration. All three are optional: addVerifyif you use email verification,Change Passwordif you allow password resets, andDeleteif you want user deletions in Auth0 to remove the row.The
Verifyscript marks an email address as verified:function verify(email, callback) {const postgres = require('pg');const conString = configuration.DATABASE_CONNECTION_STRING;postgres.connect(conString, function (err, client, done) {if (err) return callback(err);const query = 'UPDATE users SET email_verified = true WHERE email_verified = false AND email = $1';client.query(query, [email], function (err, result) {done();return callback(err, result && result.rowCount > 0);});});}The
Change Passwordscript hashes and stores a new password:function changePassword(email, newPassword, callback) {const bcrypt = require('bcrypt');const postgres = require('pg');const conString = configuration.DATABASE_CONNECTION_STRING;postgres.connect(conString, function (err, client, done) {if (err) return callback(err);bcrypt.hash(newPassword, 10, function (err, hash) {if (err) return callback(err);const query = 'UPDATE users SET password = $1 WHERE email = $2';client.query(query, [hash, email], function (err, result) {done();return callback(err, result && result.rowCount > 0);});});});}The
Deletescript removes a user by id:function remove(id, callback) {const postgres = require('pg');const conString = configuration.DATABASE_CONNECTION_STRING;postgres.connect(conString, function (err, client, done) {if (err) return callback(err);const query = 'DELETE FROM users WHERE id = $1';client.query(query, [id], function (err) {done();return callback(err);});});} - Save the scripts
Click
Save. Auth0 connects to your service or database when a user authenticates against this connection.
Verify the integration
Section titled “Verify the integration”To confirm Auth0 is working with your service or database:
- Create a user through Auth0
In the Auth0 Dashboard, go to
User Management>Users, clickCreate User, and select your custom database connection. Alternatively, sign up through an application that uses this connection. - Query your service or database to confirm the user arrived
Connect to your service or database and query the
userstable:SELECT id, email, nickname FROM users;You see a row for the user you just created, with a bcrypt hash in the
passwordcolumn, confirming that Auth0 is writing to Tiger Data.
You have successfully integrated Auth0 with Tiger Data.
Troubleshooting
Section titled “Troubleshooting”- Connection timeouts in the script editor: confirm Auth0 can reach your service or database. For Tiger Cloud, allowlist Auth0's IP addresses; self-hosted instances must be reachable from Auth0.
WrongUsernameOrPasswordErroron valid credentials: make sure theLoginandCreatescripts use the same bcrypt hashing, and that existing rows store bcrypt hashes in thepasswordcolumn.
For other connectivity and authentication issues, see Troubleshoot Tiger Cloud integrations.