Skip to content

Commit

Permalink
Merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaansyed authored and rachel-carvalho committed Oct 19, 2023
1 parent b7621ba commit 04439db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ export class EmbeddedAuthStrategy<
if (persistedSession) {
logger.debug(`Reusing existing token: ${persistedSession.accessToken}`);

if (persistedSession.isScopeChanged(config.scopes)) {
config.sessionStorage.deleteSession(persistedSession.id);

// this.redirectToInstall(request, shop);
}

if (!persistedSession.isExpired()) {
return {session: persistedSession};
}
Expand Down Expand Up @@ -223,24 +217,4 @@ export class EmbeddedAuthStrategy<
},
});
}

// this does not initiate oauth auth code flow, it just triggers managed install
// private redirectToInstall(request: Request, shop: string) {
// const {config, logger, api} = this;

// // TODO: make it unified admin
// const redirectUrl = `https://${shop}/admin/oauth/install?client_id=${config.apiKey}`;

// const isXhrRequest = request.headers.get('authorization');
// if (isXhrRequest) {
// throw redirectWithAppBridgeHeaders(redirectUrl);
// } else {
// throw redirectWithExitIframe(
// {config, logger, api},
// request,
// shop,
// redirectUrl,
// );
// }
// }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {HttpResponseError} from '@shopify/shopify-api';
import {GraphqlQueryError, HttpResponseError} from '@shopify/shopify-api';
import {redirect} from '@remix-run/server-runtime';

import type {HandleAdminClientError} from '../../../clients/admin/types';
Expand All @@ -18,6 +18,17 @@ export function handleEmbeddedClientErrorFactory({
session,
}): Promise<never> {
if (error instanceof HttpResponseError !== true) {
const gqlerror = error.response.errors[0] as any;
console.log('EXTENSIONS ERROR', gqlerror.extensions.code);
if (error instanceof GraphqlQueryError && gqlerror.extensions.code) {
throw new Response(undefined, {
status: 403,
headers: {
'Content-Type': 'application/json',
'X-Shopify-Insufficient-Access': '1',
},
});
}
params.logger.debug(
`Got a response error from the API: ${error.message}`,
);
Expand Down Expand Up @@ -50,10 +61,22 @@ export function handleEmbeddedClientErrorFactory({
},
});
} else {
// On document load, delete the access token and reload the app to retrigger
// token exchange
throw redirect(request.url);
}
}

if (error.response.code === 403) {
throw new Response(undefined, {
status: error.response.code,
headers: {
'Content-Type': 'application/json',
'X-Shopify-Insufficient-Access': '1',
},
});
}

// forward a minimal copy of the upstream HTTP response instead of an Error:
throw new Response(JSON.stringify(error.response.body), {
status: error.response.code,
Expand Down

0 comments on commit 04439db

Please sign in to comment.