As part of a custom OAuth2 flow, the user is being redirected back to a Lightning App Page with URL:
https://x-dev-ed.lightning.force.com/lightning/n/namespace__Page_Name?state=q765wYYgnvzVAsod&code=c1BF-iddZNkD1aMxVYp8p5smeAQUxITQUesC3Q_ggYHyNJzm
With a few query string params state and code.
But the page does a refresh before it loads, and the query string params are removed.
I want to access the values in state and code from the custom LWC component on the page?
I have tried looking in CurrentPageReference:
import { CurrentPageReference } from "lightning/navigation";
Using:
@wire(CurrentPageReference)
currentPageReference;
connectedCallback() {
console.log("state is: " + JSON.stringify(this.currentPageReference.state));
}
But the state object is empty {}
And, I've tried getting the value from the URL:
connectedCallback() {
const param = "code";
const paramValue = this.getUrlParamValue(window.location.href, param);
console.log(param + ": " + paramValue);
}
getUrlParamValue(url, key) {
return new URL(url).searchParams.get(key);
}
But nothing.
How can I access the values in state and code from the custom LWC component on the page?