Discourse doesn’t redirect to return_sso_url after user logs in on private site

I am using Discourse identity provider. i followed this guide Using Discourse as an identity provider (SSO, DiscourseConnect)

When on client side i redirect to

http://localhost:4200/session/sso_provider?sso=${URL_ENCODED_PAYLOAD}&sig=${HEX_SIGNATURE}

it will take me to discourse login dialog popup. I filled username and password correctly but when i click submit it closes the dialog but does not redirect me back to my own website.

But let’s suppose i am already logged in to discourse and then i open this

http://localhost:4200/session/sso_provider?sso=${URL_ENCODED_PAYLOAD}&sig=${HEX_SIGNATURE}

it will redirect me back to my website will all the correct details.

I checked few posts having similar issue but those were for wordpress but i am having my own private site.

Please help if anyone has solution
Thanks