Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set role when register a new user using strapi?

Tags:

strapi

I'm try register an user and i would like to know how can i set role as Administrator. I tried

user: {
  username: "elialber",
  email: "[email protected]",
  password: "123456789",
  role: ???
}

I'm using Angular5 and just api strapi

like image 411
Elialber Lopes Avatar asked Apr 23 '18 16:04

Elialber Lopes


1 Answers

step 1: Go to node_modules/strapi-plugin-users-permissions/controllers/Auth.js step 2: Go to on line 457(in my code) step 3: Comment params.role=role.id; like (//params.role = role.id;)

and now you can pass role id like 1 or 2 or 3 as follow

{
    "blocked":false,
    "confirmed":true,
    "username":"aziz",
    "email":"[email protected]",
    "password":"musa01010",
    "role": 2
}



and now I receive a response like:
{
    "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzQsImlhdCI6MTYwMjUzMzk0MSwiZXhwIjoxNjA1MTI1OTQxfQ.xM2tmP8PUcwABiW9lmxkjkmcmdmckMB8wlQ1YsBOQI",
    "user": {
        "id": 34,
        "username": "aziz",
        "email": "[email protected]",
        "provider": "local",
        "confirmed": true,
        "blocked": false,
        "role": {
            "id": 2,
            "name": "Public",
            "description": "Default role given to the unauthenticated user.",
            "type": "public"
        },
        "created_at": "2020-10-12T20:19:01.285Z",
        "updated_at": "2020-10-12T20:19:01.299Z"
    }
}
like image 57
Malik Musa Avatar answered Sep 22 '22 22:09

Malik Musa