Browse Source

fix: redirect to app_url in oauth-shoprenter-callback #97

Updated oauth-shoprenter-callback Edge Function to redirect to the app_url
provided by ShopRenter instead of directly to our integrations page. This
allows ShopRenter to properly redirect back to our EntryPoint with the
installation parameters.

Changes:
- After storing pending installation, redirect to app_url with sr_install
  and shopname parameters appended
- Fall back to direct /integrations redirect if no app_url is provided
- This follows ShopRenter documentation which states app_url can be
  decorated with custom query parameters

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Claude 5 months ago
parent
commit
014672f002
1 changed files with 17 additions and 4 deletions
  1. 17 4
      supabase/functions/oauth-shoprenter-callback/index.ts

+ 17 - 4
supabase/functions/oauth-shoprenter-callback/index.ts

@@ -448,10 +448,23 @@ serve(wrapHandler('oauth-shoprenter-callback', async (req) => {
       )
       )
     }
     }
 
 
-    // Redirect to frontend integrations page with installation ID
-    const redirectUrl = `${frontendUrl}/integrations?sr_install=${installationId}&shopname=${encodeURIComponent(shopname)}`
-
-    console.log(`[ShopRenter] Installation pending for ${shopname}, redirecting to: ${redirectUrl}`)
+    // Redirect to app_url (ShopRenter admin) with installation ID
+    // This allows ShopRenter to redirect back to our EntryPoint with the sr_install parameter
+    // Per ShopRenter docs: "It is possible to decorate the value of app_url with unique query string parameters"
+    let redirectUrl: string
+
+    if (app_url) {
+      // Append our installation ID to the app_url
+      const appUrlObj = new URL(app_url)
+      appUrlObj.searchParams.set('sr_install', installationId)
+      appUrlObj.searchParams.set('shopname', shopname)
+      redirectUrl = appUrlObj.toString()
+      console.log(`[ShopRenter] Installation pending for ${shopname}, redirecting to app_url: ${redirectUrl}`)
+    } else {
+      // Fallback: redirect directly to our integrations page if no app_url provided
+      redirectUrl = `${frontendUrl}/integrations?sr_install=${installationId}&shopname=${encodeURIComponent(shopname)}`
+      console.log(`[ShopRenter] Installation pending for ${shopname}, no app_url provided, redirecting to: ${redirectUrl}`)
+    }
 
 
     return new Response(null, {
     return new Response(null, {
       status: 302,
       status: 302,