dystcz / nuxt-sanctum-auth

Nuxt 3 + laravel sanctum authentication
134 stars 25 forks source link

Dynamic token and user payload key #33

Open YoungMayor opened 1 year ago

YoungMayor commented 1 year ago

Most APIs I have worked with and on use a data structure like the one below.

{
  status: 'success', 
  message: 'Login successful', 
  data: {
    token: '1|jyRcruq3NHCXj0NvgrlRAVZEO1TR9AUHqOFZ8O1j'
  }
}

This is not a global standard nor is it being used by everyone though.

But I was wondering if you could include a key on the configuration which points to the token. In the case of the above, it would be 'data.token'.

Similar would also be very useful on the get user details endpoint

Also when nuxtSanctumAuth.token is set to true, could you make the include credentials header configurable such that a user can set to include it or not.

Thanks a lot

kreejzak commented 1 year ago

Hi, I don't know if I understand this issue correctly, but you should be able to get token like this. And also you should be able to get login response via callback function.

To get user you can call $sanctumAuth.getUser().

Also all keys in responses should be configurable in nuxt.config.

YoungMayor commented 1 year ago

The current implementation gets the token from

response.token

But some API's could have it at response.data.token

So what I am suggesting is something like

On the configuration image

On the login method image

On the getUser method image

In my suggestion, lodash is used

Thanks