In Appwrite 1.0, a brand new characteristic has been added emigrate customers from different platforms like Firebase, WordPress, Supabase and so on. So on this tutorial we’re going to migrate all of the customers from WordPress to Appwrite and that is going to be tremendous simple!
Let’s do it 🦾
Step 1: Login to your WordPress web site and set up plugin
Firstly login to your WordPress web site’s admin panel and set up the free plugin named Import and export customers and clients
Step 2: Export customers from WordPress
Now in your WordPress dashboard go to Instruments>Export>Customers (in CSV format) after which Obtain Export File
Then obtain the csv file in line with your most well-liked settings
Step 3: Import Customers to Appwrite
To import customers into Appwrite, we will use any Server SDK to entry the Customers API. For this instance, we’ll use the NodeJS SDK.
Newly added features allow you to create a consumer with one in every of 7 totally different hashing algorithms. WordPress makes use of PHPass Password. So we’ll use PHPass Password in Appwrite Server SDK to import customers.
async createPHPassUser(
userId,
e-mail,
password,
identify
);
Going via the operate parameters one after the other:
- userId: The ID to assign to the brand new consumer in Appwrite. It may be customized, or you should use the SDK’s new ID.distinctive() operate to assign a randomly generated ID.
- e-mail: Corresponds to the e-mail worth from the csv file.
- password: Corresponds to the passwordHash worth from csv file.
- identify: The identify to assign to the consumer. Will be null.
Placing this all collectively, we may import all the exported customers into Appwrite like so:
const userslist = await CSVToJSON().fromFile("customers.csv");
await Promise.all(
userslist.map(async (consumer) => {
await customers.createPHPassUser(
ID.distinctive(),
consumer.user_email,
consumer.user_pass,
consumer.display_name
);
})
);
moreover it’s essential set up csvtojson
bundle to parse CSV knowledge utilizing the command under
npm i csvtojson
After all of the consumer export the Appwrite dashboard seems to be like this
So now the entire code seems to be like this
const sdk = require("node-appwrite");
const { ID } = require("node-appwrite");
const CSVToJSON = require("csvtojson");
let consumer = new sdk.Shopper();
const customers = new sdk.Customers(consumer);
consumer
.setEndpoint("Your Api Endpoint")
.setProject("Your Venture Key")
.setKey("Your Api Key")
.setSelfSigned();
const migrate = async () => {
const userslist = await CSVToJSON().fromFile("customers.csv");
await Promise.all(
userslist.map(async (consumer) => {
await customers.createPHPassUser(
ID.distinctive(),
consumer.user_email,
consumer.user_pass,
consumer.display_name
);
})
);
};
migrate()
.then((r) => console.log("Carried out!"))
.catch((e) => console.log(e));
Hope you learn to migrate customers from WordPress to Appwrite.
Remember to observe me @joysankar2001