---
title: Laravel return json not authentication – Jaeves Codelab
description: "Laravel return json not authentication Open app\\Http\\Middleware\\Authenticate.php protected function redirectTo($request)\n{\n    if( $request->is('api/*')){"
---

[Skip to content](https://jaeves.com/codelab/laravel-return-json-not-authentication#main-content)

 Close

SEARCH

[Discover Jaeves for Free](https://app.jaeves.com/login)

[![jaeves-2025-logo](https://jaeves.com/hubfs/logos/jaeves-2025-logo.svg)![jaeves-2025-logo](https://jaeves.com/hubfs/logos/jaeves-2025-logo.svg)](https://jaeves.com/)

[Discover Jaeves for Free](https://app.jaeves.com/login)

Quick results for "{search\_term}"

TABLE OF CONTENTS

loading...

Oct 2, 2023, 3:58:56 PM< 1 min read

# Laravel return json not authentication

[Previous](https://jaeves.com/codelab/what-is-crm-and-features-of-crm)

<https://jaeves.com/codelab>

[Next](https://jaeves.com/codelab/nodejs-create-env-file)

Laravel return json not authentication

Open app\\Http\\Middleware\\Authenticate.php

```
protected function redirectTo($request)
{
    if( $request->is('api/*')){
        abort(response()->json(['status' => 401, 'message' => 'Unauthorized'], 401));
    }

    if (! $request->expectsJson()) {
        return route('login');
    }else{
        abort(response()->json(['status' => 401, 'message' => 'Unauthorized'], 401));
    }
}
```

[click for more Laravel codes](https://readymadecode.com/category/website/laravel/) read about [laravel authentication](https://laravel.com/docs/9.x/authentication#invalidating-sessions-on-other-devices)

COMMENTS

## RELATED ARTICLES

[![logo](https://jaeves.com/hs-fs/hubfs/jaeves-logo-230917.png?width=140&height=45&name=jaeves-logo-230917.png "logo")](https://jaeves.com/)

Jaeves is a trailblazing AI-powered content generation tool that revolutionizes your content creation journey. Its user-friendly interface, extensive customization options, and innovative approach make it an invaluable asset for all your content needs. Transform your content strategy with Jaeves today.

All rights reserved

- [Privacy Policy](https://jaeves.com/privacy-policy)

```json
{
  "@context" : "https://schema.org",
  "@type" : "Organization",
  "address" : {
    "@type" : "PostalAddress",
    "addressCountry" : "Germany",
    "addressLocality" : "Speyer",
    "addressRegion" : "Rheinland-Pfalz",
    "postalCode" : "67346",
    "streetAddress" : "Gerhart-hauptmann-Str"
  },
  "knowsLanguage" : "en",
  "logo" : {
    "@type" : "ImageObject",
    "url" : "https://139767802.fs1.hubspotusercontent-eu1.net/hubfs/139767802/logo-2024-less-points.svg"
  },
  "name" : "Jaeves AI",
  "url" : "https://jaeves.com/codelab/laravel-return-json-not-authentication"
}
```

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "abstract" : "Laravel return json not authentication Open app\\Http\\Middleware\\Authenticate.php protected function redirectTo($request) { if( $request-&gt;is('api/*')){",
  "author" : {
    "@type" : "Person",
    "name" : "Admin"
  },
  "dateModified" : "",
  "datePublished" : "",
  "headline" : "Laravel return json not authentication",
  "image" : "",
  "inLanguage" : "en",
  "keywords" : "[Laravel]",
  "mainEntityOfPage" : {
    "@type" : "WebPage"
  },
  "name" : "Laravel return json not authentication",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://139767802.fs1.hubspotusercontent-eu1.net/hubfs/139767802/jaeves-logo-230917.png"
    },
    "name" : "Jaeves AI"
  },
  "text" : "Laravel return json not authentication Open app\\Http\\Middleware\\Authenticate.php protected function redirectTo($request) { if( $request-&gt;is('api/*')){ abort(response()-&gt;json(['status' =&gt; 401, 'message' =&gt; 'Unauthorized'], 401)); } if (! $request-&gt;expectsJson()) { return route('login'); }else{ abort(response()-&gt;json(['status' =&gt; 401, 'message' =&gt; 'Unauthorized'], 401)); } } click for more Laravel codes read about laravel authentication",
  "url" : "https://jaeves.com/codelab/laravel-return-json-not-authentication",
  "wordCount" : "135"
}
```

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Admin",
    "url" : "https://jaeves.com/codelab/author/admin"
  },
  "dateModified" : "2023-10-02T20:22:16.753Z",
  "datePublished" : "2023-10-02T19:58:56.000Z",
  "headline" : "Laravel return json not authentication – Jaeves Codelab",
  "mainEntityOfPage" : {
    "@id" : "https://jaeves.com/codelab/laravel-return-json-not-authentication",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://jaeves.com/hubfs/logo-2024-less-points.svg"
    },
    "name" : "Jaeves AI"
  }
}
```

```json
{
  "@context" : "http://schema.org",
  "@type" : "Organization",
  "description" : "Unlock the Power of AI for Content Creation. Explore Insights, Tips, and Trends on the Jaeves.com Blog. Empower Your Writing Journey Today!",
  "logo" : "https://jaeves.com/hubfs/untitled%20(4).png",
  "name" : "Jaeves AI",
  "sameAs" : [ "https://www.instagram.com/jaeves.ai", "https://www.linkedin.com/company/jaeves-ai", "https://www.youtube.com/@Jaeves_ai", "https://www.tiktok.com/@jaeves_ai" ],
  "url" : "https://jaeves.com"
}
```