Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Build Laravel Login for SPAs, Multiple Guards, 2FA and Passkeys

A practical guide to Laravel's authentication boundaries: map guards and providers to identities, use Fortify for headless flows, and choose cookies, Sanctum tokens, OAuth2, or custom JWT deliberately.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a custom Laravel frontend, Fortify supplies headless authentication flows; guards and providers determine which identity is authenticated and where it is loaded from. For a first-party SPA, Laravel documents using Fortify with the web guard and Sanctum—not adding JWT by default. Choose session cookies, API tokens, OAuth2, or a justified custom JWT design according to your clients and protocol requirements.

Choose the authentication mechanism before adding token machinery

An API does not automatically need JWT. Laravel’s authentication documentation presents custom guards as an extension point; it does not prescribe JWT for ordinary SPA or API authentication. Decide first how clients relate to your application and what the protocol must support.

As an Amazon Associate I earn from qualifying purchases.

Need Starting point What to decide
First-party browser or SPA Fortify with the web guard and Sanctum Whether requests should use Laravel’s session cookie and how the frontend will handle login and any 2FA challenge.
Mobile client or API access without OAuth2 requirements Sanctum may fit Whether a Sanctum API token meets the client and security requirements; define token handling and lifecycle for the application.
Third-party clients requiring OAuth2 protocol features Passport Which OAuth2 interoperability or grant requirements the application actually needs.
A system with a specific requirement unmet by these approaches A custom guard, potentially JWT-based Token issuance, validation, expiry, revocation, client storage, and ongoing maintenance.

Sanctum and Passport solve different needs and can coexist with Laravel browser authentication. Laravel’s guidance generally favors Sanctum for first-party browser/SPAs and many mobile or API cases, while Passport is intended for applications that need OAuth2 features. The framework’s authentication documentation explains its custom-guard extension point and this Sanctum-versus-Passport distinction: Laravel authentication documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep guards, providers and authentication flows distinct

Laravel’s documentation puts the key distinction plainly: “Guards define how users are authenticated for each request.” A guard describes how a request is authenticated. A provider retrieves the authenticatable user from persistent storage. A guard references a provider, so its configuration must match the identity store and request type it is intended to serve.

#1 Best Overall
FIDO2 U2F Security Key Passkey Two-Factor Authentication (2FA) USB Key PIN+Touch (Non-Biometric) USB-A Type TrustKey T110
  • Security Key : Protect your online accounts against unauthorized access by using FIDO2 and U2F authentication with T110. It's the world's most protective security key that works with windows, Mac OS, Linux as well as Chrome, Firefox, Edge and many other major browsers.
  • Certified with the new FIDO2 standard, T110 provides the benefit of fast login and strong protection against phishing, account takeover as well as many other online attactks.
  • Works with : Bank of America, Github, Google, Microsoft, DUO, Twitter, Facebook, Dropbox, Apple, ebay, BINANCE, mor and more.
  • Fits USB-A port : Insert the T110 security key into the USB-A port of each service and log in conveniently with one touch
  • For the driver download and user guide, please visit TrustKey Solutions Home support page.
  • Guards answer how: for example, whether a request is authenticated through the application’s session or another mechanism.
  • Providers answer from where: they retrieve the user record or other authenticatable identity.
  • Route middleware chooses the guard: Laravel’s auth middleware can name a configured guard. Routes should use the guard intended for their audience and request flow.

For customer, administrator, or other separate populations, map each route group to the appropriate guard and provider. Do not assume that creating multiple guards automatically separates authorization rules or gives every authentication flow the right identity context: explicitly design those boundaries.

Fortify’s configured guard has an additional constraint: it must implement IlluminateContractsAuthStatefulGuard. That requirement matters when selecting a guard for Fortify; a custom guard that authenticates a different kind of request is not automatically suitable for Fortify’s stateful login flows. See Laravel Fortify documentation alongside the framework’s authentication documentation.

Rank #2
FIDO2 U2F Security Key Passkey Two-Factor Authentication (2FA) USB Key PIN+Touch (Non-Biometric) USB-C Type TrustKey T120
  • Security Key : Protect your online accounts against unauthorized access by using FIDO2 and U2F authentication with T120. It's the world's most protective security key that works with windows, Mac OS, Linux as well as Chrome, Firefox, Edge and many other major browsers.
  • Certified with the new FIDO2 standard, T120 provides the benefit of fast login and strong protection against phishing, account takeover as well as many other online attactks.
  • Works with : Bank of America, Github, Google, Microsoft, DUO, Twitter, Facebook, Dropbox, Apple, ebay, BINANCE, mor and more.
  • Fits USB-C port : Insert the T120 security key into the USB-C port of each service and log in conveniently with one touch
  • For the driver download and user guide, please visit TrustKey Solutions Home support page.

Use Fortify as the headless authentication backend

Fortify provides authentication routes and controllers rather than a frontend. Your custom UI sends requests to those routes, while Fortify supplies backend flows such as registration, password reset, email verification, and two-factor authentication. Laravel describes the arrangement this way: “If you choose to install Fortify, your user interface will make requests to Fortify’s authentication routes that are detailed in this documentation in order to authenticate and register users.”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Identify your clients. Decide whether the frontend is a first-party browser SPA, a mobile app, or an API client outside your control.
  2. Choose the request authentication model. For a Fortify-powered SPA, Laravel documents the web guard with Sanctum. Sanctum can authenticate first-party requests using Laravel’s session cookie and can also inspect an API token.
  3. Map identities to routes. Configure each guard with the appropriate provider and attach the intended guard to its route group. Keep administrative and customer identities distinct where the application requires it.
  4. Build the frontend around backend states. Handle successful login, validation or authentication errors, and any response that requires the user to complete a two-factor challenge. Use the route and configuration behavior for the Fortify version installed by the application.
  5. Add stronger authentication deliberately. Decide whether the account should support TOTP, passkeys, or both, and provide enrollment, recovery, and fallback paths appropriate to the application.

Fortify’s 2FA detail below is documented in Laravel 11.x Fortify material, while the passkey material is from Laravel 13.x. Check the documentation corresponding to your installed package and framework version before relying on exact route or configuration behavior.

Rank #3
Sale
Thetis Nano-A FIDO2 Security Key Hardware Passkey Device with USB Type A, TOTP/HOTP, FIDO2.0 Two Factor Authentication 2FA MFA, Works with Windows/mac/iOS/Android/Linux/Gmail/Facebook/GitHub/Coinbase
  • Ultra-Compact FIDO2 Security Key - Plug-and-stay or carry on a keychain. This USB-A hardware security key offers portable, always-on protection for desktop and mobile use. (Item Size: 0.75 X 0.74 IN x 0.25 IN)
  • USB-A Hardware Key for All Devices - Works with USB-A ports on PC, Mac, Android, and other laptop/notebook device. Enables secure, cross-platform login with FIDO2.0 passkey support.
  • FIDO Certified Security Key - Meets FIDO and FIDO2 standards. Works with Google, Microsoft, GitHub, Dropbox, and more. Please check service compatibility before purchase.
  • Passwordless Login with Passkey - Supports passkey login via WebAuthn and CTAP2. Enjoy password-free sign-ins where supported. Not all websites or services currently support passkeys.
  • Advanced Multi-Factor Authentication - Offers 200 FIDO2 passkey slots and 50 OATH-TOTP slots. Strong, flexible 2FA/MFA support across various apps and authentication platforms.

Implement Fortify’s TOTP two-factor flow as a frontend state machine

The documented Fortify 2FA feature uses TOTP: a compatible authenticator app generates a six-digit numeric code. Enrollment is not just a frontend toggle. The user enables the feature, scans a QR code, and—when confirmation is configured—must submit a valid code to complete setup. Recovery codes provide an alternate route when the authenticator device is unavailable.

  1. Protect changes to 2FA settings. Fortify’s default feature settings require password confirmation before a user changes those settings.
  2. Start enrollment and display the QR code. For an XHR frontend, the Fortify documentation describes retrieving the QR code from a dedicated endpoint. Present it only in the authenticated account-security flow.
  3. Confirm enrollment when configured. Ask the user to enter a current six-digit code. Treat setup as incomplete until the server accepts it when confirmation is enabled.
  4. Show and manage recovery codes. Retrieve recovery codes through the documented endpoint and provide a way to regenerate them. Explain that they are for regaining access if the authenticator device is lost.
  5. Handle the login challenge. Include a challenge state in the login flow. The frontend posts either an authenticator code or a recovery code to the challenge endpoint and responds to the result rather than treating the initial password submission as the only possible login outcome.

The cited Fortify documentation describes TOTP and recovery codes; it does not establish SMS or email as Fortify’s second factor. Consult the version-specific Fortify 2FA documentation for the relevant endpoints and feature settings.

Rank #4
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Add passkeys with the WebAuthn registration and login ceremonies

Laravel 13.x Fortify documentation describes passkey registration and login using WebAuthn. A passkey can use a platform authenticator—such as Face ID, Touch ID, or Windows Hello—or a hardware security key. A dedicated hardware key is optional; a compatible platform authenticator may already be available on the user’s device.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a custom frontend, the client and server participate in a ceremony: request options from the backend, perform the credential operation in the browser, then submit the serialized result for server verification. The official @laravel/passkeys JavaScript package supports the browser-side ceremonies.

Best Value
Yubico - YubiKey 5C NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5C NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5C NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5C NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts
  1. Meet the user-model contract. The model must implement Fortify’s PasskeyUser contract and use PasskeyAuthenticatable.
  2. Set deployment-specific WebAuthn configuration. The relying-party ID and allowed origins must match the deployed domain and permitted origins. Configuration also includes a user-handle secret and operation timeout.
  3. Implement registration and login as separate ceremonies. Fetch the corresponding options, invoke the browser operation through the supported client package, and send the serialized result back for verification.
  4. Plan recovery and rate limits. Keep an account recovery path for users who cannot use a passkey. Fortify applies rate limiting to passkey routes.

Incorrect domain or origin configuration can prevent browser credentials from working on the deployed site, so configure against the real deployment rather than assuming a development origin will transfer unchanged. The specifics are in Laravel 13.x Fortify passkey documentation.

When a custom JWT guard is justified

Laravel’s authentication documentation demonstrates registering a custom jwt driver and configuring a guard to use it. That example shows how to extend the framework; it does not select a third-party JWT package, define a complete token lifecycle, or say JWT is necessary for Fortify, an API, or a multi-guard application.

Before implementing a custom token guard, write down the requirement it solves that a session, Sanctum token, or Passport’s OAuth2 features does not. Then specify how tokens are issued and validated, when they expire, how access is revoked, and where each client stores them. The documentation’s custom-driver example alone does not settle those security and operational choices. Do not label a design “JWT sessions” as if it were Laravel’s default session mode: JWT-based request authentication is a separate design decision.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Review the design before shipping

  • Every protected route uses a configured guard that matches its client and identity population.
  • Each guard references the provider for the intended user store.
  • Fortify uses a guard that implements StatefulGuard; for a documented SPA setup, use the web guard with Sanctum.
  • The frontend can represent login challenges, TOTP enrollment confirmation, and recovery-code use where enabled.
  • Passkey relying-party ID and allowed origins match the deployment, and the user model satisfies Fortify’s passkey contract.
  • Passport is selected for a real OAuth2 protocol requirement, not merely because the application exposes API routes.
  • A custom JWT guard has a defined token expiry, revocation, client-storage, and maintenance policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.