2

I have a domain x.com in which i am taking the username and password. Storing these in localstorage or cookies. Once the user logs in I have a link in which once user clicks that its redirected to y.com in another tab.Notice the domains are different. I want to make use of the variables I have set in x.com for y.com. How can I achieve this in angular Js? Localstorage is not cross domain is there any other solution? If yes can you please give an example

ian dsouza
  • 187
  • 2
  • 4
  • 14
  • can you initialise a cookie in a [`z.com`](https://stackoverflow.com/a/3342225/8495123) domain? – Aleksey Solovey May 16 '18 at 10:49
  • Z.com?? I am considering two domains as examples x.com and y.com. If you are telling to initialise a cookie, are cookies cross domain is Angular js? – ian dsouza May 16 '18 at 10:51
  • https://meta.stackexchange.com/questions/260153/global-auth-is-dead-long-live-universal-login – Umair Abid May 16 '18 at 10:55
  • You can do it with cookies or with authorization header, but it depends on your server side, not on Angular side. Angular just will help you to send the information the server needs – Hosar May 16 '18 at 10:59
  • I have resolved it using the old document.cookie and mentioned the other domain y.com in the Domain Attribute – ian dsouza May 18 '18 at 12:12

1 Answers1

0

I've created an NPM module, which allows you to share locally-stored data across domains:

By using an iframe hosted on Domain A, you can store all of your user data on Domain A, and reference that data by posting requests to the Domain A iframe.

Thus, Domains B, C, etc. can inject the iframe and post requests to it to store and access the desired data. Domain A becomes the hub for all shared data.

With a domain whitelist inside of Domain A, you can ensure only your dependent sites can access the data on Domain A.

The trick is to have the code inside of the iframe on Domain A which is able to recognize which data is being requested. The README in the above NPM module goes more in depth into the procedure.

Hope this helps!

jmealy
  • 583
  • 1
  • 5
  • 14