JeffBeltran / sanctum-tokens

Simple Nova Plugin to generate a Laravel Sanctum Personal Access Token
https://novapackages.com/packages/jeffbeltran/sanctum-tokens
51 stars 25 forks source link

Empty Token Name #44

Closed anibalsanchez closed 2 years ago

anibalsanchez commented 3 years ago

Hi,

The token name is required, but the dialogue allows to enter the empty name.

When you enter the empty value:

Argument 1 passed to ...Models\\User::createToken() must be of the type string, null given, called in /app/vendor/jeffbeltran/sanctum-tokens/src/Http/SanctumController.php on line 27

A simple workaround is re-defining the createToken as:

    /**
     * Create a new personal access token for the user.
     *
     * @param  string  $name
     * @param  array  $abilities
     * @return \Laravel\Sanctum\NewAccessToken
     */
    public function createToken_d(?string $name = null, array $abilities = ['*'])
    {
        if (!$name) {
            $name = '- Empty Name -';
        }

        $token = $this->tokens()->create([
            'name' => $name,
            'token' => hash('sha256', $plainTextToken = Str::random(40)),
            'abilities' => $abilities,
        ]);

        return new NewAccessToken($token, $token->getKey().'|'.$plainTextToken);
    }
JeffBeltran commented 3 years ago

Thanks @anibalsanchez, i'll have to think on this one but i might just make that a required field or i could have a random word generator used on empty names... let me play with this and i'll get back to you

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 2.0.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: