|
19 | 19 | * using a script tag with type="module".
|
20 | 20 | * - When packages are added or removed from the server, follow these steps
|
21 | 21 | * again to ensure that the list of scripts and links here is up to date.
|
22 |
| - * - Add postMessage code to communicate with the main origin (where the server |
23 |
| - * is hosted) via iframe to get the login credentials, and set them in |
24 |
| - * localStorage to log ourselves in on the newly attached client. Note, set CORS |
25 |
| - * headers in the meteor server for security to allow only your own domains to |
26 |
| - * access the main origin in an iframe, otherwise anyone can use an iframe to |
27 |
| - * get your credentials on any website you visit. |
| 22 | + * - Add postMessage code (load-meteor-auth.js) to communicate with the main |
| 23 | + * origin (where the server is hosted) via iframe to get the login credentials, |
| 24 | + * and set them in localStorage to log ourselves in on the newly attached |
| 25 | + * client. Note, set CORS headers in the meteor server for security to allow |
| 26 | + * only your own domains to access the main origin in an iframe, otherwise |
| 27 | + * anyone can use an iframe to get your credentials on any website you visit. |
28 | 28 | */
|
29 | 29 |
|
30 | 30 | {
|
31 |
| - const isDev = location.host.includes('localhost') |
32 |
| - const mainOrigin = isDev ? 'http://localhost:8765' : 'https://lume.io' |
33 |
| - |
34 | 31 | __meteor_runtime_config__ = JSON.parse(
|
35 | 32 | decodeURIComponent(
|
36 | 33 | '%7B%22meteorRelease%22%3A%22METEOR%403.1.2%22%2C%22gitCommitHash%22%3A%227d31a24753d18307d7bc7f56adc080a3fc86b3b5%22%2C%22meteorEnv%22%3A%7B%22NODE_ENV%22%3A%22production%22%2C%22TEST_METADATA%22%3A%22%7B%7D%22%7D%2C%22PUBLIC_SETTINGS%22%3A%7B%7D%2C%22debug%22%3Afalse%2C%22ROOT_URL%22%3A%22https%3A%2F%2Flume-io-20950.nodechef.com%2F%22%2C%22ROOT_URL_PATH_PREFIX%22%3A%22%22%2C%22reactFastRefreshEnabled%22%3Atrue%2C%22autoupdate%22%3A%7B%22versions%22%3A%7B%22web.browser%22%3A%7B%22version%22%3A%22465660ba89c48b54b5ea176a5beefeab8c2947e5%22%2C%22versionRefreshable%22%3A%221952018619999f014765d73c14db1f446971e849%22%2C%22versionNonRefreshable%22%3A%22465660ba89c48b54b5ea176a5beefeab8c2947e5%22%2C%22versionReplaceable%22%3A%221952018619999f014765d73c14db1f446971e849%22%7D%2C%22web.browser.legacy%22%3A%7B%22version%22%3A%227e45b3eb2b7c0bb2dba58ca7ed0a0b0d218bfced%22%2C%22versionRefreshable%22%3A%221952018619999f014765d73c14db1f446971e849%22%2C%22versionNonRefreshable%22%3A%227e45b3eb2b7c0bb2dba58ca7ed0a0b0d218bfced%22%2C%22versionReplaceable%22%3A%221952018619999f014765d73c14db1f446971e849%22%7D%7D%2C%22autoupdateVersion%22%3Anull%2C%22autoupdateVersionRefreshable%22%3Anull%2C%22autoupdateVersionCordova%22%3Anull%2C%22appId%22%3A%22q04iv5yj40nv1s0iw0f%22%7D%2C%22appId%22%3A%22q04iv5yj40nv1s0iw0f%22%2C%22isModern%22%3Atrue%7D',
|
37 | 34 | ),
|
38 | 35 | )
|
39 | 36 |
|
| 37 | + // mainOrigin is defined in importmap.js |
40 | 38 | __meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL = mainOrigin
|
41 | 39 | __meteor_runtime_config__.ROOT_URL = mainOrigin
|
42 | 40 |
|
|
114 | 112 | <script type="text/javascript" src="${mainOrigin}/packages/launch-screen.js?hash=${cacheBust}"></script>
|
115 | 113 | <script type="text/javascript" src="${mainOrigin}/global-imports.js?hash=${cacheBust}"></script>
|
116 | 114 |
|
117 |
| - <script type="module"> |
118 |
| - const mainOrigin = '${mainOrigin}' |
119 |
| -
|
120 |
| - if (!localStorage.getItem('Meteor.loginToken')) { |
121 |
| - const iframe = document.createElement('iframe') |
122 |
| - iframe.style.display = 'none' |
123 |
| - iframe.src = mainOrigin |
124 |
| - console.log('iframe src', iframe.src, mainOrigin) |
125 |
| - document.body.append(iframe) |
126 |
| -
|
127 |
| - // listen for credentials message |
128 |
| - window.addEventListener('message', event => { |
129 |
| - if (event.data.type === 'loginCredentials') { |
130 |
| - console.log('received credentials', event.data) |
131 |
| - localStorage.setItem('Meteor.loginToken', event.data.token) |
132 |
| - localStorage.setItem('Meteor.loginTokenExpires', event.data.expires) |
133 |
| - localStorage.setItem('Meteor.userId', event.data.userId) |
134 |
| - } |
135 |
| - }) |
136 |
| -
|
137 |
| - await new Promise(resolve => { |
138 |
| - iframe.addEventListener('load', async () => { |
139 |
| - while (!localStorage.getItem('Meteor.loginToken')) { |
140 |
| - // Post a message to the iframe to get credentials. |
141 |
| - console.log('post message for credentials') |
142 |
| - //iframe.contentWindow.postMessage( { type: 'getLoginCredentials' }, {targetOrigin: mainOrigin}) |
143 |
| - iframe.contentWindow.postMessage( { type: 'getLoginCredentials' }, {targetOrigin: '*'}) |
144 |
| - //iframe.contentWindow.postMessage( { type: 'getLoginCredentials' } ) |
145 |
| - await new Promise(resolve => setTimeout(resolve, 50)) |
146 |
| - } |
147 |
| -
|
148 |
| - resolve() |
149 |
| - }) |
150 |
| - }) |
151 |
| -
|
152 |
| - iframe.src = '' |
153 |
| - iframe.remove() |
154 |
| - } |
155 |
| -
|
156 |
| - // This includes imports such as the <blaze-component> element. |
157 |
| - await import ('${mainOrigin}/entry.js') |
158 |
| -
|
159 |
| - </script> |
| 115 | + <script type="module" src="/load-meteor-auth.js"></script> |
160 | 116 | `)
|
161 | 117 | }
|
0 commit comments