#john_70817

1 messages · Page 1 of 1 (latest)

placid mountainBOT
candid coral
#

Hi there, can you tell me more about the problems taht you are facing? what prevent from passing the data if you open a new tab?

elder abyss
#

I have a nodejs server message like the one in the sample: router.get("/oauth-link", async (req, res) => {
const state = uuidv4();
req.session.state = state;
req.session.authorization = req.headers.authorization;
console.log("/oauth-link: auth = %s", req.headers.authorization);
const redirectUrl = 'https://' + req.get('host') + '/onboard/authorize-oauth';
const args = new URLSearchParams({
state,
client_id: process.env.STRIPE_CLIENT_ID,
scope: "read_write",
response_type: "code",
redirect_uri: redirectUrl
})
const url = https://connect.stripe.com/oauth/authorize?${args.toString()};
console.log("Cookies = %s", JSON.stringify(req.cookies)); // remove later
return res.redirect(303, url);
});

#

And I open this in a new tab in my frontend: const oauthLinkURL = '<our_website>/onboard/oauth-link';
const headers = {
Authorization: Bearer ${tokenss},
};
const newWindow = window.open(oauthLinkURL, '_blank');
if (newWindow) {
newWindow.postMessage({ headers }, serverURL);
}

#

But the backend route (oauth-link) does not detect this header

#

So my hunch is that the header is not passed if i open a new tab

#

All of this code works for mobile, just having issue with web

candid coral
#

I don't see a direct connection between using tab and not passing headers.

elder abyss
#

From what ive read, you can't pass headers when you open a new tab

#

Maybe I'm wrong

#

But I don't see the header get to the backend

#

Here is what the sampel stripe project does:

#

fetch("/get-oauth-link", {
method: "GET",
headers: {
"Content-Type": "application/json"
}
})
.then(response => response.json())
.then(data => {
if (data.url) {
window.location = data.url;

#

This opens the url in the same page

#

I want it to open in a different tab

candid coral
#

You can open a link in a tab if you set target=”_blank” attribute in the <a> tag

elder abyss
#

ok, i was able to open a new tab using a different code:

#

fetch("https://mywebsite/onboard/oauth-link-return", {
method: "GET",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + tokenss
}
})
.then(response => response.json())
.then(data => {
if (data.url) {
// Open the URL in a new window
const newWindow = window.open(data.url, "_blank");
if (newWindow) {
// Focus the new window (optional)
newWindow.focus();
}
}
});

#

I'm just checking if the entire flow works now, should I open a new message if i have issues with the flow after this?