React : How to pass safely Authorization Access Token from PHP to React component ajax call? [closed]

I need to convert a Laravel Edit Profile page partially to React, I am using react-hook-form for the form, the form has an ajax call ( POST api/v1/user/profile/edit ) that needs the authorization header with access token, the access token is generated by Laravel Passport like:

    public function login( LoginRequest $request )
    {
        // Parameter(s)
        $data = [
            'email'             => $request->email,
            'password'          => $request->password,
        ];

        // Login & Return User Model
        $user = $this->users->login( $data );

        // Create + Get Access Token
        $access_token = $user->createToken('user_access_token', [])
            ->accessToken;

        // Transform Result
        $result = $this->loginTransformer->transform( $user );

        // RETURN Result
        return $this->sendResponse($result, trans('api.user.login_success'))
            ->header('Authorization', 'Bearer '.$access_token);

How do I safely pass the Laravel Passport access token from Laravel to the React component? Thanks



Read more here: https://stackoverflow.com/questions/66273931/react-how-to-pass-safely-authorization-access-token-from-php-to-react-componen

Content Attribution

This content was originally published by yelnn at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: