Create new Auth0 User during Woocommerce checkout

Hello,

I would like to implement a create new Auth0 user feature with Auth0 after the the Woo Commerce purchase is completed, as I don’t want the user to login into my app after they have completed their purchase through woocommerce in wordpress app.

I have done some studies on the Auth0-wordpress plugin, however, I am not sure how this can be done. Can someone provide advise on what to do if we want to create a new Auth0 User so that I can link the User to my vanilla SPA to login?

Any ideas would be appreciated. Thanks.

1 Like

Hi @lynnchin,

Thanks for reaching out to the Auth0 Community!

Sure! You can create a new user by using the Auth0 Management API’s Create a User endpoint.

In this scenario, you will need to call the Create a User endpoint after the user has completed their purchase on your app.

Please let me know if you have any further questions.

Thanks,
Rueben

Thanks @rueben.tiow! Appreciate your help.

I wonder is there any code snippet or examples I can follow to do this in wordpress?

Cheers

Hi @lynnchin,

Thank you for your reply.

Yes! I attached a code snippet using an Axios POST request to create a new user.

const axios = require('axios');
let data = JSON.stringify({
  "email": "testuser@example.com",
  "password": "SECRET",
  "connection": "Username-Password-Authentication"
});

let config = {
  method: 'post',
  url: 'https://YOUR_DOMAIN/api/v2/users',
  headers: { 
    'Authorization': 'Bearer MGMT_API_TOKEN', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

I hope this helps!

Thanks,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.