Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option rolesVar to support a response role type object. #300

Open
themaxaboy opened this issue Sep 25, 2020 · 2 comments
Open

Option rolesVar to support a response role type object. #300

themaxaboy opened this issue Sep 25, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@themaxaboy
Copy link
Contributor

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.

@d0whc3r
Copy link
Owner

d0whc3r commented Sep 25, 2020

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

@themaxaboy
Copy link
Contributor Author

themaxaboy commented Oct 1, 2020

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"];
    }
  }

@d0whc3r d0whc3r self-assigned this Nov 15, 2020
@d0whc3r d0whc3r added enhancement New feature or request help wanted Extra attention is needed labels Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants