简体   繁体   English

如何仅在user_id上登录,而不是每次在API调用时传递JWT AUTH令牌

[英]How to get only logged in user_id instead passing JWT AUTH Token everytime on APIs call

I am developing APIs and I'm using JWT Auth Token when i logged in JWT gives me token and each time i passed this token on URL PRM on Postman so that i can add required data with logged in user id. 我正在开发API,并且当我登录JWT时会使用JWT Auth令牌,并且每次我在Postman的 URL PRM上传递此令牌时,都可以使用登录的用户ID添加所需的数据。

But i dont want to pass this token everytime this should pick user_id automatically when saving data and i dont need to pass token everytime when saving data into database against user_id. 但是我不想每次都传递此令牌,这应该在保存数据时自动选择user_id,并且我不需要每次针对user_id将数据保存到数据库时都传递令牌。

This is my one of api call: 这是我的api调用之一:

    public function addPage(Request $request)
     {
    $fieldsValidation = [

        'page_url'  =>  'required|unique:page_master,page_url',
        'page_name' => 'required',
    ];
    $validator = Validator::make($request->all(), $fieldsValidation);

    if ($validator->fails()) {
        $resultArray = [
            'status' => 0,
            'message' => $validator->errors()->first(),
            'dataArray' => []
        ];
    } else {

        $page = new Page($request->all());

        $user = User::find($request->user_id);
        $user->pageUrl()->save($page);

        $resultArray = ['status' => 1, 'message' => 'Page url added!', 'dataArray' => $page];
    }
    return Response::json($resultArray, 200);
}

if i dont pass the token it sayas call to member function pageurl() on null. 如果我不传递令牌,它说的是对null成员函数pageurl()的调用。 its hurting me and i am using laravel 5.5. 它伤害了我,我正在使用laravel 5.5。 with JWT Auth package. 使用JWT Auth软件包。 ANy help would be appreciated: 任何帮助,将不胜感激:

If you are passing user_id then: 如果要传递user_id则:

$user = User::find( $request->user_id);

$user->pageUrl()->save($page);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取登录用户的当前user_id - How to get current user_id of logged in user Laravel JWT auth 刷新令牌时获取用户 ID - Laravel JWT auth get User ID when refreshing token Laravel - 如果我只有一个带有 email 和 ID 的 JWT 令牌,我如何为用户设置 Auth::attempt - Laravel - How can i set the Auth::attempt to a user if i only have a JWT token with the email and the id "如何使用来自 twitter 的访问令牌获取 user_id?" - How to get user_id using access token from twitter? 如何从 JWT access_token(bshaffer oauth 库)中提取 user_id - How to extract user_id from JWT access_token (bshaffer oauth library) 如何在社交引擎中获取当前用户(已登录)的user_id? - How to get the current user's (who is logged in) user_id in social engine? 如何提取session登录用户的当前user_id? - How to extract the current user_id of the user logged in that session? CODEIGNITER如何在登录user_ID时将user_ID插入mySQL - CODEIGNITER how to insert user_ID to mySQL when that user_ID is logged in @if(Auth :: user()== $ image-> user_id)即使登录用户的ID为1并且$ image-> user_id的ID也为1 - @if (Auth::user() == $image->user_id) doesn't work even though logged user has id of 1 and $image->user_id has id 1 as well 如何使用此代码获取user_id - How to get user_id with this code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM