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

Update install guide #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benbjurstrom
Copy link

Thanks for the package, it's been working really well for me so far. Had a little trouble setting things up initially so I thought I'd share my notes.

@benbjurstrom
Copy link
Author

Installation

1. Install the package via composer

composer require spatie/laravel-passkeys

2. Add the package's interface and trait to your Authenticatable model

// app/Models/User.php
namespace App\Models;

use Spatie\LaravelPasskeys\Models\Concerns\HasPasskeys;
use Spatie\LaravelPasskeys\Models\Concerns\InteractsWithPasskeys;
// ...

class User extends Authenticatable implements HasPasskeys
{
    use HasFactory, Notifiable, InteractsWithPasskeys;

    // ... 
}

3. Publish and run the migrations

php artisan vendor:publish --tag="passkeys-migrations"
php artisan migrate

4. Install the JavaScript dependencies

npm install @simplewebauthn/browser

5. Import the JavaScript dependencies

// resources/js/bootstrap.js
import {
    browserSupportsWebAuthn,
    startAuthentication,
    startRegistration,
} from '@simplewebauthn/browser'

window.browserSupportsWebAuthn = browserSupportsWebAuthn
window.startAuthentication = startAuthentication
window.startRegistration = startRegistration

6. Re-build the JavaScript assets

npm run build

7. Add the package provided routes

// routes/web.php
Route::passkeys();

8. Add the authentication component to the login view

<!--Laravel Breeze: resources/views/livewire/pages/auth/login.blade.php-->
<x-authenticate-passkey />

9. Add the passkey management component to the profile view

<!--Laravel Breeze: resources/views/profile.blade.php-->
<livewire:passkeys />

10. (Optional) Publish the views for custom styling

php artisan vendor:publish --tag="passkeys-views"

11. (Optional) Set the AUTH_MODEL in your .env file

Set the AUTH_MODEL in your .env file to the class name of the model that should be authenticated using passkeys.

AUTH_MODEL=App\Models\User

12. (Optional) Publish the config file

php artisan vendor:publish --tag="passkeys-config"

@belzaaron
Copy link

Good to add here that this is for @simplewebauthn/browser < v11. (11 was released within a few weeks of commenting: https://github.com/MasterKale/SimpleWebAuthn/releases/tag/v11.0.0)

4. Install the JavaScript dependencies

npm install @simplewebauthn/browser

So this would become npm install @simplewebauthn/browser@10 or equivalent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants