Axios/InertiaJS 请求出现错误 401 (Heroku)

发布于 2025-01-09 07:06:19 字数 889 浏览 3 评论 0原文

我在 heroku 上部署了我的网站。它有一个聊天系统并且可以在本地工作,但是当部署到 Heroku 时,返回所有用户的请求却返回错误 401。 GET https://website.herokuapp.com/api/user/me 401(未经授权)

我尝试从 api 路由中删除 auth:sanctum 但没有任何改变。 我将在下面给出一些代码。

Route::group(['middleware' => ['auth:sanctum']], function(){
    Route::get('/user/me', [UserController::class, 'me'])->name('users.me');
});
public function me()
    {
        $userLogged = Auth::user();

        return response()->json(
            [
                'user' => $userLogged,
            ],
            Response::HTTP_OK
        );
    }

在网络控制台上,我在网络区域中收到一条消息:“未经身份验证。”

PS:如果有帮助,我使用本文进行部署:https://dev.to/rabeeaali/how-to-deploy-inertia-js-to-heroku-2cdn

I deployed my website on heroku. It has a chat system and works locally but when deploying to Heroku the request that returns me all the users returns instead an error 401.
GET https://website.herokuapp.com/api/user/me 401 (Unauthorized)

I tried to remove the auth:sanctum from the api route but nothing changed.
I'll give some of the code below.

Route::group(['middleware' => ['auth:sanctum']], function(){
    Route::get('/user/me', [UserController::class, 'me'])->name('users.me');
});
public function me()
    {
        $userLogged = Auth::user();

        return response()->json(
            [
                'user' => $userLogged,
            ],
            Response::HTTP_OK
        );
    }

And on the web console I get a message: "Unauthenticated." in the network area

PS: If it helps I used this article to deploy: https://dev.to/rabeeaali/how-to-deploy-inertia-js-to-heroku-2cdn

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文