Send referrer path and origin through login flow
3520b605
1 file(s) · +9 −2
| 258 | 258 | method: "POST", |
|
| 259 | 259 | headers: { "Content-Type": "application/json" }, |
|
| 260 | 260 | credentials: "include", |
|
| 261 | + | referrerPolicy: "no-referrer-when-downgrade", |
|
| 261 | 262 | body: JSON.stringify({ publicationUri }), |
|
| 262 | 263 | }); |
|
| 263 | 264 | ||
| 264 | 265 | const data = await response.json(); |
|
| 265 | 266 | ||
| 266 | 267 | if (response.status === 401 && data.authenticated === false) { |
|
| 267 | - | // Redirect to the hosted subscribe page to complete OAuth |
|
| 268 | - | window.location.href = data.subscribeUrl; |
|
| 268 | + | // Redirect to the hosted subscribe page to complete OAuth, |
|
| 269 | + | // passing the current page URL (without credentials) as returnTo. |
|
| 270 | + | const subscribeUrl = new URL(data.subscribeUrl); |
|
| 271 | + | const pageUrl = new URL(window.location.href); |
|
| 272 | + | pageUrl.username = ""; |
|
| 273 | + | pageUrl.password = ""; |
|
| 274 | + | subscribeUrl.searchParams.set("returnTo", pageUrl.toString()); |
|
| 275 | + | window.location.href = subscribeUrl.toString(); |
|
| 269 | 276 | return; |
|
| 270 | 277 | } |
|
| 271 | 278 |