FROM CACHE - en_header

Rest API in Laravel APP and problem with tokens for rest api

sebastiandev
Shopify Partner
2 0 1

Hi,

 

We create app using the project on laravel: https://github.com/Shopify/shopify-app-php

 

We have settings page with options created via Polaris. It looks great. But when I click save I want send request to endpoint.

 

This is request to endpoint like here: https://github.com/Shopify/shopify-app-php/blob/main/routes/web.php#L110

 

I see that exists middleware for verify active session: https://github.com/Shopify/shopify-app-php/blob/main/app/Http/Middleware/EnsureShopifySession.php

So I need to send request with header Authorization Barer with token. But I have problem how I should provide for fetch request header with token?


I tried to like this script:

 

render() {
     const app = useAppBridge();
     getSessionToken(app).then(async (token) => {
          alert(token);
     });

     //...

 

but I see errors:

 

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.

but this script works:

 

function ExamplePage() {
     const app = useAppBridge();
     getSessionToken(app).then(async (token) => {
          alert(token);
     });

     return <div>Example Page</div>
}

 

How I should provide token to rest request?

Replies 0 (0)