In Appwrite 1.0, a new feature has been added to migrate users from other platforms like Firebase, WordPress, Supabase etc to Appetite. So in this tutorial we are going to migrate all the users from WordPress to Appwrite and this is going to be super easy!
Let's do it 🦾
Step 1: Login to your WordPress website and install plugin
Firstly login to your WordPress website's admin panel and install the free plugin named Import and export users and customers
Step 2: Export users from WordPress
Now in your WordPress dashboard go to Tools>Export>Users (in CSV format) and then Download Export File
Then download the csv file according to your preferred settings
Step 3: Import Users to Appwrite
To import users into Appwrite, we can use any Server SDK to access the Users API. For this example, we will use the NodeJS SDK.
Newly added functions let you create a user with one of 7 different hashing algorithms. Wordpress uses PHPass Password. So we will use PHPass Password in Appwrite Server SDK to import users.
async createPHPassUser(
userId,
email,
password,
name
);
Going through the function parameters one by one:
- userId: The ID to assign to the new user in Appwrite. It can be custom, or you can use the SDK's new ID.unique() function to assign a randomly generated ID.
- email: Corresponds to the email value from the csv file.
- password: Corresponds to the passwordHash value from csv file.
- name: The name to assign to the user. Can be null.
Putting this all together, we could import all of the exported users into Appwrite like so:
const userslist = await CSVToJSON().fromFile("users.csv");
await Promise.all(
userslist.map(async (user) => {
await users.createPHPassUser(
ID.unique(),
user.user_email,
user.user_pass,
user.display_name
);
})
);
additionally you need to install csvtojson
package to parse CSV data using the command below
npm i csvtojson
After all the user export the Appwrite dashboard looks like this
So now the whole code looks like this
const sdk = require("node-appwrite");
const { ID } = require("node-appwrite");
const CSVToJSON = require("csvtojson");
let client = new sdk.Client();
const users = new sdk.Users(client);
client
.setEndpoint("Your Api Endpoint")
.setProject("Your Project Key")
.setKey("Your Api Key")
.setSelfSigned();
const migrate = async () => {
const userslist = await CSVToJSON().fromFile("users.csv");
await Promise.all(
userslist.map(async (user) => {
await users.createPHPassUser(
ID.unique(),
user.user_email,
user.user_pass,
user.display_name
);
})
);
};
migrate()
.then((r) => console.log("Done!"))
.catch((e) => console.log(e));
Hope you learn how to migrate users from WordPress to Appwrite.
Don't forget to follow me @joysankar2001
Top comments (0)