Use this file to discover all available pages before exploring further.
The Delete script implements the defined function to delete a specified user from an external database. We recommend naming this function deleteUser.The script is only used in a legacy authentication scenario, and is required if you want to delete a user from Auth0 and your external database in the same operation.
This is a pseudo-JavaScript example of how you could implement the deleteUser function. For language-specific examples, read Language-specific script examples.
function deleteUser(id, callback) { // Send user identifier to external database API let options = { url: "https://example.com/api/deleteUser", body: { id: id } }; send(options, (err, profileData) => { // Return error in callback if deletion failed if (err) { return callback(new Error("My custom error message.")); } // Return null value in callback if deletion succeeded return callback(null); });}
function remove (id, callback) { // This script remove a user from your existing database. // It is executed whenever a user is deleted from the Management API or Auth0 dashboard. // // There are two ways that this script can finish: // 1. The user was removed successfully: // callback(null); // 2. Something went wrong while trying to reach your database: // callback(new Error("my error message")); var msg = "Please implement the Delete script for this database " + "connection at https://manage.auth0.com/#/connections/database"; return callback(new Error(msg));}
ASP.NET Membership Provider (MVC3 - Universal Providers)
function remove(id, callback) { const sqlserver = require('tedious@1.11.0'); const Connection = sqlserver.Connection; const Request = sqlserver.Request; const TYPES = sqlserver.TYPES; const connection = new Connection({ userName: 'the username', password: 'the password', server: 'the server', options: { database: 'the db name', encrypt: true, // Required to retrieve userId needed for Membership entity creation rowCollectionOnRequestCompletion: true } }); connection.on('debug', function(text) { // if you have connection issues, uncomment this to get more detailed info // console.log(text); }).on('errorMessage', function(text) { // this will show any errors when connecting to the SQL database or with the SQL statements console.log(JSON.stringify(text)); }); connection.on('connect', function(err) { if (err) return callback(err); executeDelete(['Memberships', 'Users'], function(err) { if (err) return callback(err); callback(null); }); }); function executeDelete(tables, callback) { const query = tables.map(function(table) { return 'DELETE FROM ' + table + ' WHERE UserId = @UserId'; }).join(';'); const request = new Request(query, function(err) { if (err) return callback(err); callback(null); }); request.addParameter('UserId', TYPES.VarChar, id); connection.execSql(request); }}
ASP.NET Membership Provider (MVC4 - Simple Membership)
function remove(id, callback) { const sqlserver = require('tedious@1.11.0'); const Connection = sqlserver.Connection; const Request = sqlserver.Request; const TYPES = sqlserver.TYPES; const connection = new Connection({ userName: 'the username', password: 'the password', server: 'the server', options: { database: 'the db name', encrypt: true, // Required to retrieve userId needed for Membership entity creation rowCollectionOnRequestCompletion: true } }); connection.on('debug', function (text) { // if you have connection issues, uncomment this to get more detailed info // console.log(text); }).on('errorMessage', function (text) { // this will show any errors when connecting to the SQL database or with the SQL statements console.log(JSON.stringify(text)); }); connection.on('connect', function (err) { if (err) return callback(err); executeDelete(['webpages_Membership', 'UserProfile'], function (err) { if (err) return callback(err); callback(null); }); }); function executeDelete(tables, callback) { const query = tables.map(function (table) { return 'DELETE FROM ' + table + ' WHERE UserId = @UserId'; }).join(';'); const request = new Request(query, function (err) { if (err) return callback(err); callback(null); }); request.addParameter('UserId', TYPES.VarChar, id); connection.execSql(request); }}
function remove(id, callback) { //this example uses the "pg" library //more info here: https://github.com/brianc/node-postgres const postgres = require('pg'); const conString = 'postgres://user:pass@localhost/mydb'; 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) { // NOTE: always call `done()` here to close // the connection to the database done(); return callback(err); }); });}
function remove (id, callback) { // this example uses the "tedious" library // more info here: http://pekim.github.io/tedious/index.html var Connection = require('tedious@1.11.0').Connection; var Request = require('tedious@1.11.0').Request; var TYPES = require('tedious@1.11.0').TYPES; var connection = new Connection({ userName: 'your-user@your-server-id.database.windows.net', password: 'the-password', server: 'your-server-id.database.windows.net', options: { database: 'mydb', encrypt: true } }); connection.on('debug', function (text) { console.log(text); }).on('errorMessage', function (text) { console.log(JSON.stringify(text, null, 2)); }).on('infoMessage', function (text) { console.log(JSON.stringify(text, null, 2)); }); connection.on('connect', function (err) { if (err) { return callback(err); } var query = 'DELETE FROM users WHERE id = @UserId'; var request = new Request(query, function (err) { if (err) { return callback(err); } callback(null); }); request.addParameter('UserId', TYPES.VarChar, id); connection.execSql(request); });}