Embedding in iFrame with the SSO - does not redirect to selected dashboard

Grafana, IAM, NEXT.JS, NGNIX running in docker.

NEXT.JS and Grafana are configured to authenticate via the IAM.
Grafana is configured by using the GENERIC_OAUTH.

User log into the application (NEXT.JS) and then goes to the page where the Grafana dashboard is embeded via the iFrame.

Howerver the first time when user does it the SSO takes place

The SSO works but I expect user to be redirected to the dashboard ( redirectTo:/d-solo/ceg3vz1sqtywwe/ws20-test?orgId=1&from=2025-03-17T05:31:33.900Z&to=2025-03-17T11:31:33.900Z&timezone=browser&panelId=1&__feature.dashboardSceneSolo)
while it is redirected to the grafana root (https://localhost/grafana/).

This redirecting happens only on the first time user visits the page with embedded Grafana, later he is redirected to the dashboard (as expected).

Did anywone have something similar, how to solve it?

It looks like after redirecting form OAuth, Grafana goes to the root instead of going to the its start position.