vue-auth-plugin icon indicating copy to clipboard operation
vue-auth-plugin copied to clipboard

Option rolesVar to support a response role type object.

Open themaxaboy opened this issue 5 years ago • 2 comments
trafficstars

When I use vue-auth-plugin with strapi headless cms, the login api gets a role response as a object type.

user: {
    blocked: false,
    confirmed: false,
    created_at: "2020-09-25T20:58:22.478Z",
    email: "[email protected]",
    id: 1,
    provider: "local",
    role: {
        description: "Default role given to authenticated user.",
        id: 1,
        name: "Authenticated",
        type: "authenticated",
    },
    updated_at: "2020-09-25T20:58:22.487Z",
    username: "user"
}

I think the rolesVar option should be set to a string with dot for access the object like lodash get.

_.get(object, 'a.b.c', 'default');

For me rolesVar is "role.type"

An alternative is to add a customRole like customToken.

customToken: (response) => response.data['token'] customRole: (response) => response.data['user']['role']['type']

Please consider thank you and sorry for my writing.

themaxaboy avatar Sep 25 '20 22:09 themaxaboy

Thank you very much for open an issue with this good aproach I will implement the two variants

d0whc3r avatar Sep 25 '20 23:09 d0whc3r

Now I can fix this problem with workaround by custom fetchData

loginData: {
    url: "/auth/local",
    method: "POST",
    redirect: "/user",
    headerToken: "Authorization",
    fetchUser: true,
    customToken: response => response.data["jwt"],
    fetchData: response => {

      //Replace role object with role type

      response.data.user.role = response.data.user.role.type;
      return response.data["user"];
    }
  }

themaxaboy avatar Oct 01 '20 09:10 themaxaboy