|
|
@@ -87,14 +87,21 @@ async function sendOTPEmail(email, otp, userName) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// Environment URLs
|
|
|
+const BACKEND_URL = process.env.BACKEND_URL || (process.env.NODE_ENV === 'production'
|
|
|
+ ? 'https://shopcall-ai-backend.vercel.app'
|
|
|
+ : 'http://localhost:3000');
|
|
|
+
|
|
|
+const FRONTEND_URL = process.env.FRONTEND_URL || (process.env.NODE_ENV === 'production'
|
|
|
+ ? 'https://shopcall.ai'
|
|
|
+ : 'http://localhost:8080');
|
|
|
+
|
|
|
// Shopify Configuration
|
|
|
const config = {
|
|
|
apiKey: process.env.SHOPIFY_API_KEY,
|
|
|
apiSecret: process.env.SHOPIFY_API_SECRET,
|
|
|
scopes: 'read_products,write_products,read_orders,write_orders,read_customers,write_customers',
|
|
|
- redirectUri: process.env.NODE_ENV === 'production'
|
|
|
- ? 'https://shopcall-ai-backend.vercel.app/auth/shopify/callback'
|
|
|
- : 'https://shopcall-ai-backend.vercel.app/auth/shopify/callback'
|
|
|
+ redirectUri: `${BACKEND_URL}/auth/shopify/callback`
|
|
|
};
|
|
|
|
|
|
// ShopRenter Configuration
|
|
|
@@ -102,15 +109,9 @@ const shoprenterConfig = {
|
|
|
clientId: process.env.SHOPRENTER_CLIENT_ID,
|
|
|
clientSecret: process.env.SHOPRENTER_CLIENT_SECRET,
|
|
|
scopes: 'product:read product:write customer:read customer:write order:read order:write webhook:read webhook:write',
|
|
|
- redirectUri: process.env.NODE_ENV === 'production'
|
|
|
- ? 'https://shopcall-ai-backend.vercel.app/auth/shoprenter/callback'
|
|
|
- : 'http://localhost:3000/auth/shoprenter/callback',
|
|
|
- entryPoint: process.env.NODE_ENV === 'production'
|
|
|
- ? 'https://shopcall-ai-backend.vercel.app/auth/shoprenter'
|
|
|
- : 'http://localhost:3000/auth/shoprenter',
|
|
|
- uninstallUri: process.env.NODE_ENV === 'production'
|
|
|
- ? 'https://shopcall-ai-backend.vercel.app/auth/shoprenter/uninstall'
|
|
|
- : 'http://localhost:3000/auth/shoprenter/uninstall'
|
|
|
+ redirectUri: `${BACKEND_URL}/auth/shoprenter/callback`,
|
|
|
+ entryPoint: `${BACKEND_URL}/auth/shoprenter`,
|
|
|
+ uninstallUri: `${BACKEND_URL}/auth/shoprenter/uninstall`
|
|
|
};
|
|
|
|
|
|
// Store nonces temporarily (use Redis or database in production)
|
|
|
@@ -537,8 +538,8 @@ app.get('/auth/woocommerce', securedSession, (req, res) => {
|
|
|
app_name: 'ShopCall.ai',
|
|
|
scope: 'read_write',
|
|
|
user_id: req.user.id,
|
|
|
- return_url: 'https://shopcall.ai/dashboard',
|
|
|
- callback_url: 'https://shopcall-ai-backend.vercel.app/auth/woocommerce/callback?platform=' + platform + '&shop_url=' + shop_url + '&phone_number=' + phone_number + '&package=' + package
|
|
|
+ return_url: `${FRONTEND_URL}/dashboard`,
|
|
|
+ callback_url: `${BACKEND_URL}/auth/woocommerce/callback?platform=${platform}&shop_url=${shop_url}&phone_number=${phone_number}&package=${package}`
|
|
|
};
|
|
|
const query_string = querystring.stringify(params).replace(/%20/g, '+');
|
|
|
const redirect_url = store_url + endpoint + '?' + query_string;
|
|
|
@@ -766,7 +767,7 @@ app.get('/auth/shoprenter/callback', async (req, res) => {
|
|
|
console.log(`Successfully stored ShopRenter connection for: ${shopname}`);
|
|
|
|
|
|
// Redirect to dashboard
|
|
|
- res.redirect('https://shopcall.ai/dashboard?connection=success&platform=shoprenter');
|
|
|
+ res.redirect(`${FRONTEND_URL}/dashboard?connection=success&platform=shoprenter`);
|
|
|
|
|
|
} catch (error) {
|
|
|
console.error('ShopRenter OAuth callback error:', error);
|
|
|
@@ -887,7 +888,7 @@ app.get('/auth/shopify/callback', async (req, res) => {
|
|
|
// TODO: Save tokenJson.access_token securely
|
|
|
console.log(`Successfully authenticated shop: ${normalizedShop}`);
|
|
|
|
|
|
- res.redirect(`https://shopcall.ai/`);
|
|
|
+ res.redirect(`${FRONTEND_URL}/`);
|
|
|
} catch (error) {
|
|
|
console.error('OAuth callback error:', error);
|
|
|
res.status(500).json({
|