Hi Tyler Bell
We are trying to add Google SSO to our mobile application using memberstack, but looks like it send the user data to the opener tab here https://client.memberstack.com/auth/callback?state=
using this script
https://client.memberstack.com/auth/callback?state=
const error = JSON.parse('{"message":"Something went wrong. Please try again."}');
if (error) {
window.opener.postMessage({ error }, "*");
} else {
const data = JSON.parse(unescape('[object Object]'))
window.opener.postMessage({ data }, "*");
}
window.close();
Is there any chances to don’t open a new tab and send the data to a parent mobile application?
For example:
window.ReactNativeWebView.postMessage for React Native, and
window.webkit.messageHandlers.cordova_iab.postMessage for Cordova
Thanks in advance
1 comment
I resolved this by making modifications to the memberstack/dom lib
Create a browser listener to get that message and parse the html to get the success (token) or error (error message)
Success:
const getSuccessMessage = (message) => { try { const regex = new RegExp(/unescape\('([^']+)'\)/); if (regex.test(message)) { const match = regex.exec(message); const extractedString = match[1]; const encodedString = extractedString .replace('"unescape(', "") .replace('"', ""); const unscapeString = unescape(encodedString); const parsedString = JSON.parse(unscapeString); return parsedString; } } catch (error) { return null; } };Error:
const getErrorMessage = (message) => { try { const regex = new RegExp(/"message":"([^"]*)"/); if (regex.test(message)) { const match = regex.exec(message); const extractedString = match[1]; return extractedString; } } catch (error) { return null; } };That's all, hope this helps
Please sign in to leave a comment.