I am developing an app for BigCommerce and currently have a specific store name in my redirect URI. When a user installs the app, they are redirected to this predefined store. However, I want to make my app support any store where it is installed and dynamically redirect the user to their respective store after installation.
Here’s what I’ve tried so far:
Specifying a fixed redirect_uri with a hardcoded store name.
The problem is that this approach doesn’t work for multiple stores.
How can I dynamically determine the store name or URL and ensure the user is redirected back to their specific store after installation?
Any code examples or guidance would be greatly appreciated.
2
Answers
To redirect users to their specific store after installation, use the store_hash provided in the OAuth callback. After the user installs the app and grants permissions, BigCommerce returns the store_hash in the callback. You can then use to construct the store’s URL and redirect the user to their specific store’s dashboard or any other page, instead of relying on a hardcoded store name.
Thanks
namespace AppHttpMiddleware;
use Closure;
class BigCommerceCallbackHandler
{
public function handle($request, Closure $next)
{
if ($request->has(‘context’)) {
$context = $request->get(‘context’); // e.g., "stores/abc123"
$storeHash = explode(‘/’, $context)[1]; // Extract "abc123"
$request->merge([‘store_hash’ => $storeHash]);
}
}