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

Tokens list not displayed #85

Open
juanr-yes opened this issue Apr 18, 2023 · 7 comments
Open

Tokens list not displayed #85

juanr-yes opened this issue Apr 18, 2023 · 7 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@juanr-yes
Copy link

Hi! thanks in advance for this cool package and for the hard work.

I've trying to use it but seems like its having some issues:

Once i'm on the User resource and after inserting
SanctumTokens::make()

When i'm on the detail page and after creating a token, nothing gets displayed while i get a js error on the console:
TypeError: Cannot read properties of undefined (reading 'length') even when the token has been successfully created.

I'm on Laravel 8, Laravel Nova 4 and latest sanctum-tokens.

Looking forward to hear from you! Thanks again.

image

@JeffBeltran
Copy link
Owner

if i get time i'll try and duplicate this but typically i have found is that if there are issues it is normally related to the sanctum configuration. if you can get me more details it might help me point you in the right direction

@JeffBeltran JeffBeltran added help wanted Extra attention is needed good first issue Good for newcomers labels Apr 21, 2023
@juanr-yes
Copy link
Author

Hi Jeff! Thanks for answering me.

I believe i have a very straight-forward sanctum configuration but i'll gladly share whatever you think might guide us into a solution!

Have a great weekend

@kostamilorava
Copy link

kostamilorava commented Aug 20, 2023

Hey @juanr-yes,

Too late for party, but if anyone else will have this issue, check your network tab in developer tools - you should have something like: /nova-vendor/sanctum-tokens/tokens/users/ID_OF_USER

Check what is being returned there (I had 302 redirect), It should return JSON. If in routes configuration you have something like:

Route::get('{any}', function () {
    return redirect()->route('home');
})->where('any', '.*');

It overrides routes that are needed for this package (at least it was case for me).

@juanr-yes
Copy link
Author

hi @kostamilorava , hope you are doing great. Thanks for your input, although im not sure we are talking about the same issues; i am looking at the network tab and the "sanctum-tokens" request and got a 200 response and, as stated in the beginning, the typeerror continues

@kostamilorava
Copy link

hi @kostamilorava , hope you are doing great. Thanks for your input, although im not sure we are talking about the same issues; i am looking at the network tab and the "sanctum-tokens" request and got a 200 response and, as stated in the beginning, the typeerror continues

Alright, on fresh installed project, it seems to work properly. I checked the line where Vue throws that error, and I am pretty sure we are talking about same error, but just reason is different. Maybe you have some middleware that changes responses or wraps them.

Vue is not able to iterate through tokens and produces that error. Do you have same structure as mine? Here is correct response (copied and pasted whole response) that works and may help you diagnose your problem:

{
    "id": 2,
    "name": "IOT Device",
    "email": "[email protected]",
    "email_verified_at": null,
    "created_at": "2023-08-20T20:37:57.000000Z",
    "updated_at": "2023-08-20T20:37:57.000000Z",
    "tokens": [
        {
            "id": 1,
            "tokenable_type": "App\\Models\\User",
            "tokenable_id": 2,
            "name": "Name of token",
            "abilities": [
                "ability-name"
            ],
            "last_used_at": "2023-08-22T10:11:08.000000Z",
            "expires_at": null,
            "created_at": "2023-08-21T18:36:33.000000Z",
            "updated_at": "2023-08-22T10:11:08.000000Z"
        }
    ]
}

@juanr-yes
Copy link
Author

hey @kostamilorava , thanks a lot!! you're completely right about beign related to Vue not beign able to iterate the "tokens" property, which i whas hiding by not declaring it on $visible while on the model. Thanks to the repo owner as well.

@stevelacey
Copy link

@JeffBeltran I ran into this issue, the reason was because I have a $visible = [...] definition in my user model that doesn't include tokens so maybe it'd be a good idea for you to call makeVisible('tokens') in addition to with('tokens') from your controller

For now I've put this in my User::booted 🤢

static::retrieved(function ($user) {
    if (Request::is('nova-vendor/sanctum-tokens/*')) {
        $user->makeVisible('tokens');
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants