Okay, thatβs still not how you use the latest app bridge regardless of the language
You donβt need to create the app that way. If you checkout the docs for the latest version I linked.
You add two lines to the head of the file and then it automatically adds the Shopify instance to the window and you can access methods on it.
It will also automatically instrument fetch calls with access tokens too
Please check the documentation I linked earlier as you are using a mix of the old and new app bridge, in your examples. This is why your app is not functioning as you expect.
Here is a fully upgraded example for you to try.
I think theres just confusion around using the new CDN only loaded version which adds shopify onto the window and older NPM packages youβve been trying to use.
<?php
session_set_cookie_params([
'lifetime' => 0,
'path' => '/',
'domain' => 'purchasetheme.com',
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
session_start();
if (!isset($_SESSION['shop']) || !isset($_SESSION['host'])) {
die("Session expired. Please reinstall the app.");
}
$shop = $_SESSION['shop'];
$host = $_SESSION['host'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Dummy Data Dashboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="shopify-api-key" content="f695b1811cb0c61d054d4a3e70f1035c" />
<script src="https://cdn.shopify.com/shopifycloud/app-bridge.js"></script>
</head>
<body>
<h2>Dummy Data App
<?php echo $shop;?> =>
<?php echo $host;?>
</h2>
<div id="status">Verifying token...</div>
<script>
document.addEventListener("DOMContentLoaded", async function () {
// Just to show something that app bridge loaded
shopify.toast.show('Loaded Shopify');
try {
// With new App Bridge, the auth token is automatically added
const response = await fetch("/dummydata/auth/verify_token.php", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({})
});
// check the status code of the response is okay
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
// Continue to check the response body
const result = await response.json();
if (result.success) {
console.log("β Verified:", result);
document.getElementById("status").innerText = `β Verified for ${result.shop}`;
} else {
console.warn("β Verification failed:", result.message);
document.getElementById("status").innerText = `β Verification failed: ${result.message}`;
}
} catch (err) {
console.error("β Token fetch/verify failed:", err);
document.getElementById("status").innerText = "β Token fetch/verify failed.";
}
});
</script>
</body>
</html>