RBAC - login as "Author"

System Information
  • Strapi Version: 3.4.0
  • Operating System: Centos 7
  • Database: SQLite
  • Node Version: 12.20.0
  • NPM Version: 6.14.8
  • Yarn Version:

Hello,
Per Strapi RBAC document, I was able to do the following:

  1. Create – a user as “Author” – bob
  2. Create collection type – “profile”
  3. Set the relationship between “Author” and “profile”
  4. I was able to login as Author (i.e. bob) and create a new profile
  5. Now ONLY bob has access to the collection type – i.e. “profile”
    Note – Everything works using Strapi GUI.

Question:

  1. How do l programmatically login as “Author” – i.e. bob and retrieve bob’s profile?
    Here is the test code:
    //=======================================
    window.testLoginButton = function (){
    console.log("\n");
    console.log(“start — Request API”);
    // Request API.
    axios
    .post(‘http://my.domain.com:1337/auth/local’, {
    identifier: ‘4086238212@my.domain.com’,
    password: ‘Abc1234567890’,
    })
    .then(response => {
    // Handle success.
    console.log(‘Well done!’);
    console.log(‘User profile’, response.data.user);
    console.log(‘User token’, response.data.jwt);
    })
    .catch(error => {
    // Handle error.
    console.log(‘An error occurred:’, error.response);
    });
    console.log(“end — Request API”);
    console.log("\n");
    console.log(“Request API – wait for callback function”);
    }
    //=================================
    I am getting this error:
    spread.js:25 POST http://my.domain.com:1337/auth/local 400 (Bad Request)

Please note – this is a very simple use case – i.e. each “Author” can only retrieve their “profile”.
Please let me know if you need any additional information?

Thanks
Aelix

You are using the users-permissions plugin here, not the admin.