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

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 75 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,98 @@ This package contains a Livewire component to generate passkeys. Make sure you h

## Installation

You can install the package via composer:
### 1. Install the package via composer

```bash
composer require spatie/laravel-passkeys
```

Next, you must set the `AUTH_MODEL` in your `.env` file to the class name of the model that should be authenticated using passkeys.
### 2. Add the package's interface and trait to your Authenticatable model

```bash
AUTH_MODEL=App\Models\User
```php
// 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;

// ...
}
```

Next, you publish the migration by the package with:
### 3. Publish and run the migrations

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

After the migration has been published you can create the `passkeys` table by running the migrations:
### 4. Install the JavaScript dependencies

```bash
php artisan migrate
npm install @simplewebauthn/browser
```

### 5. Import the JavaScript dependencies

```javascript
// 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

```bash
npm run build
```

### 7. Add the package provided routes

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

### 8. Add the authentication component to the login view

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

### 9. Add the passkey management component to the profile view

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

### 10. (Optional) Publish the views for custom styling

```bash
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.
```bash
AUTH_MODEL=App\Models\User
```

Optionally, you can publish the config file using:
### 12. (Optional) Publish the config file

```bash
php artisan vendor:publish --tag="passkeys-config"
Expand Down Expand Up @@ -103,12 +170,6 @@ return [
];
```

Optionally, you can publish the views using

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

## Usage

There are two parts to using passkeys in your Laravel app: creating a passkey and authenticating using a passkey.
Expand Down