FROM CACHE - en_header

React with Rails application. Making http requests to AuthenticatedController (`RequireKnownShop`)

Lasvad
Excursionist
14 0 4

Hi all,

Been trying to get this working as I believe it should but am struggling. I've got a react frontend, rails backend application ( via React-rails ). The application is installed to my dev store and I'm able to access it. I've added the Shopify app gem and included a couple concerns to my AuthenticatedController following a couple guides.

```

class AuthenticatedController < ApplicationController

# include ShopifyApp::Authenticated
include ShopifyApp::EmbeddedApp
include ShopifyApp::RequireKnownShop
include ShopifyApp::ShopAccessScopesVerification
end
```
 
What I can't seem to figure out is, how do I make an http request to a controller is based off of AuthenticatedController to satisfy these concerns? Whenever I make an GET or POST request, I get the following redirection
 
Started POST "/example_endpoint" for 123.123.123.123 at 2021-09-06 02:31:19 -0500
┃ Processing by ExampleEndpointController#create as */*
┃ Parameters: {"myExampleParams"=>{"title"=>"", "body"=>"", "shop"=>"test-store.myshopify.com"}}
┃ Redirected to https://123.123.123.123.ngrok.io/login
┃ Filter chain halted as :check_shop_domain rendered or redirected.            <----------- looks like the concern is failing on the check_shop_domain check.
┃ Completed 302 Found in 1ms (ActiveRecord: 0.0ms | Allocations: 341)
 
Started GET "/login" for 123.123.123.123 at 2021-09-06 02:31:19 -0500
┃ Processing by ShopifyApp::SessionsController#new as */*
┃ Rendering /Users/<username>/.gem/ruby/3.0.1/gems/shopify_app-18.0.2/app/views/shopify_app/sessions/new.html.erb
 
When I remove the concerns, I'm able to make any http request to my Rails server. The issue only comes up when those concerns are active. I'm currently of the mind set that all my controllers should be using the AuthenticatedController ( even ones that will not to fetching or updating order/product data on Shopify ). I've created a session tokens via `
useAppBridge` / `getSessionToken` and passed it into the header for the http request in hopes that this would allow me to access my endpoint that lives within AuthenticatedController but no luck.

```
method: <GET, POST, PUT>,
credentials: 'include' as RequestCredentials,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}` < ---- this is where i've been putting the JWT token
},
body: JSON.stringify({
...data
})
```
 
What am I missing here? On initial load ( when refreshing the page which loads the html.erb containing react), I can breakpoint into the `def index` of MyController<AuthenticatedController, and I have access to `current_shopify_domain`, but on any request from the react on the frontend it doesn't pass the concern and gets redirected... I feel like I must be missing or over thinking some piece, as searching for answers regarding this has resulted in very little results. This should be straight forward imo, I just cannot seem to get this to work.
 
Thanks for all for helping. Please let me know anymore details are required.
 
Thanks.
Replies 0 (0)