I am using memberstack to gate pages on a website I built using dorik. Dorik has made it very difficult and I can't use memberstack data attributes on my log in/out buttons. I have used custom code to get these buttons to work. and they work great, hide/ appear depending on login behaviour but for some reason when I log in, rather that redirecting to dashboard, it is taking me down to my pricing table and replacing the /affiliate-dashboard slug with /#pricing. I have checked my redirect options in member stack and they are all correct. in the console it is returning these errors :
|
Unhandled Promise Rejection: [object Object] |
|
|
• Unhandled Promise Rejection: [object Object] |
|
|
Unhandled Promise Rejection: [object Object] |
|
|
Unhandled Promise Rejection: [object Object] |
|
|
Unhandled Promise Rejection: [object Object] |
|
|
Refused to set unsafe header "cookie"
here is the custom code I used:
<script> const dashboardUrl = "/affiliate-dashboard"; function getLinks() { function hide(el) { function show(el) { async function updateNavButtons() { const { login, signup, logout } = getLinks(); const ms = window.$memberstackDom; if (!ms) return; const member = await ms.getCurrentMember(); if (member && member.data) { hide(login); } else { show(login); } // Wait for Memberstack to load const waitForMemberstack = setInterval(async function () { attempts++; if (window.$memberstackDom) { clearInterval(waitForMemberstack); await updateNavButtons(); } if (attempts > 20) { clearInterval(waitForMemberstack); console.error("Memberstack did not load"); } }, 300); // Handle button clicks const link = e.target.closest("a"); if (!link) return; const href = link.href; const ms = window.$memberstackDom; if (!ms) return; // LOGIN e.preventDefault(); await ms.openModal("LOGIN"); // Watch for successful login const member = await ms.getCurrentMember(); if (member && member.data) { clearInterval(checkLogin); window.location.href = dashboardUrl; } }, 500); } // SIGNUP e.preventDefault(); await ms.openModal("SIGNUP"); } // LOGOUT e.preventDefault(); await ms.logout(); window.location.href = "/"; } }); });
any ideas on what is happening, is It something to do with Dorik intercepting the redirect? |
|
1 comment
I talked with rey.memberstack.com and received the following advice. I think it's good advice (based on the data provided.) I don't know anything about Dorik and we've never tested Memberstack on a Dorik site:
Root Cause of the Redirect Issue
Your custom code is not explicitly setting a post-login redirect URL in the
openModal("LOGIN")call. When you usems.openModal("LOGIN")without specifying a redirect, Memberstack defaults to the first redirect URL configured in your Memberstack dashboard (likely your pricing page or homepage).Additionally, the "Unhandled Promise Rejection" errors and "Refused to set unsafe header 'cookie'" warnings suggest:
/affiliate-dashboardto/#pricing.Solution: Explicitly Set Redirects in Your Code
Update your custom code to force the redirect after login by:
ms.loginMemberEmailPassword()orms.openModal()with aredirectUrlparameter.window.location.hrefafter login (since Dorik may interfere).Updated Code Example:
Key Fixes:
Explicit
redirectUrlinloginMemberEmailPassword(): Memberstack will now automatically redirect to/affiliate-dashboardafter a successful login, bypassing Dorik’s URL interference.onAuthChangefor Reliable Redirects: Uses Memberstack’s built-in auth listener instead of polling, avoiding race conditions with Dorik.Cookie Handling: The
useCookies: trueinitialization ensures authentication works across domains (critical for Dorik).Avoid
window.location.hrefPost-Login: Dorik’s client-side routing likely intercepts these redirects. Let Memberstack handle it via theredirectUrlparameter.Debugging Steps if It Still Fails:
Check Dorik’s Console for Errors: Dorik might be throwing errors that block Memberstack. Look for:
Refused to set unsafe header(cookie blocking)Uncaught TypeError(Dorik overridingwindow.location)Test Without Dorik’s Routing:
Verify Memberstack’s Redirect Settings: Double-check in your Memberstack Dashboard that:
/affiliate-dashboardis set as the default login redirect for all plans.Fallback: Use
ms.redirectToMemberStack(): If Dorik absolutely refuses to cooperate, you can use Memberstack’s direct redirect:Why This Works:
redirectUrlparameter ensures the redirect happens before Dorik’s router interferes.onAuthChangelistener avoids race conditions by reacting to auth state changes in real-time.useCookies: true) bypasses Dorik’s security restrictions.Next Steps:
YOUR_PUBLIC_KEYandYOUR_APP_IDin the code.Would you like me to clarify any part of the fix? 😊
Please sign in to leave a comment.