Installation | laravel-suspicious-login-rust | Spatie       

 SPATIE  

laravel-suspicious-login-rust
=============================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-suspicious-login-rust](https://spatie.be/docs/laravel-suspicious-login-rust/v1)  Installation

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-suspicious-login-rust/v1) 

  Installation    
- [ Introduction ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/support-us)
- [ Installation ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/usage)
- [ Detection ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/detection)
- [ Testing ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/changelog)
- [ Customization ](https://spatie.be/docs/laravel-suspicious-login-rust/v1/customization)

 Installation
============

###  On this page 

1. [ Provider and migration ](#content-provider-and-migration)
2. [ Updating an earlier checkout ](#content-updating-an-earlier-checkout)

- Requires Rust 1.99 or newer and `laravel-rust =0.1.0`.
- Install from Git. Publication to crates.io is disabled.

```
[dependencies]
spatie-laravel-suspicious-login = { git = "https://github.com/spatie/laravel-suspicious-login-rust", default-features = false, features = ["mysql"] }
```

- Pin a reviewed revision. Select `sqlite` (the default), `mysql` or `postgres` to match the application.
- Native model connections determine storage; the default model uses the application's default database.
- History queries use the write connection to avoid replica lag changing assessments.

Provider and migration
--------------------------------------------------------------------------------------------------------------------------

```
use spatie_suspicious_login::{DeviceCookie, service_provider};

let app = laravel::Application::configure()
    .with_providers(|providers| { providers.add(service_provider()); })
    .with_middleware(|middleware, _| {
        middleware.web(|web| { web.append(DeviceCookie); });
    });
```

- The provider sets typed environment defaults, registers a lazy singleton and validates configuration during boot.
- Application config overrides run after package defaults.
- The provider never creates tables or chooses account providers or routes.

Add an application-owned migration:

```
use laravel::db::AnyTransaction;

pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> {
    spatie_suspicious_login::migrate(tx).await
}
```

- Register this with normal application migration discovery. It creates `suspicious_login_attempts` with account identifiers, success/blocked flags, indexed `observed_at` Unix seconds and the serialized observation in `data`.
- A custom model can use `migrate_table(tx, "custom_table")` on its selected connection. No migration executes on provider boot.
- `DeviceCookie` must run inside `EncryptCookies`. Never exempt `suspicious_login_device` from encryption. Configure an application key.
- The cookie is HttpOnly, SameSite=Lax, secure for HTTPS requests, and lasts 365 days. A stolen cookie is not proof of identity; a cleared cookie looks like a new device.
- The stateless `UserAgentFingerprinter` does not need this middleware.
- Restrict framework trusted proxies to known networks. The package uses `Request::ip()` and never parses forwarded addresses itself.
- Enable Cloudflare location headers only when your edge removes untrusted incoming headers and supplies its own.

Updating an earlier checkout
--------------------------------------------------------------------------------------------------------------------------------------------

- Replace matches on `Error::InvalidDriver(String)` with `UnknownLocationDriver`, `UnknownReputationSource`, `MissingAbuseIpDbKey` or `MaxMindDatabase { path, source }`.
- Change the Cargo dependency name from `spatie-suspicious-login` to `spatie-laravel-suspicious-login` and regenerate the lockfile. Imports remain `spatie_suspicious_login`.
- Replace provider instances such as `SuspiciousLogin::default()` with `service_provider()`. Put configuration in the application's `with_config` callback.
- Replace the old table before using the new schema, or write an application data migration. The old `created_at`/`trusted` layout and serialized reason enum are not read by the new model. Back up history before migrating; the package never drops or converts it automatically.
- The explicit `trust` API is removed. Successful, unblocked observations establish familiarity. Blocked and failed attempts never do.
- Warning actions now queue native mail. Configure a queue connection and worker for durable asynchronous delivery. A sync connection runs immediately.
- Defaults now include location lookups. Set `SUSPICIOUS_LOGIN_GEOLOCATION=null` if sending IPs to ipinfo is not appropriate for your application.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
