mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 14:56:55 +08:00
7b97a8fca2
* fix: Fixed bug in passport access * fix: resolved issues with postMessage and static urls
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
import { HANDLE_SUCCESSFUL_LOGIN } from 'coral-framework/constants/auth';
|
|
import { getStaticConfiguration } from 'coral-framework/services/staticConfiguration';
|
|
import { createPostMessage } from 'coral-framework/services/postMessage';
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const staticConfig = getStaticConfiguration();
|
|
const { BASE_ORIGIN: origin } = staticConfig;
|
|
const postMessage = createPostMessage(origin);
|
|
|
|
// Get the auth element and parse it as JSON by decoding it.
|
|
const auth = document.getElementById('auth');
|
|
const doc = document.implementation.createHTMLDocument('');
|
|
doc.body.innerHTML = auth.innerText;
|
|
|
|
// Auth state is contained within the node.
|
|
const { err, data } = JSON.parse(doc.body.textContent);
|
|
if (err) {
|
|
const errDiv = document.createElement('div');
|
|
if (err.message) {
|
|
errDiv.innerText = `${err.name}: ${err.message}`;
|
|
} else {
|
|
errDiv.innerText = JSON.stringify(err);
|
|
}
|
|
document.body.appendChild(errDiv);
|
|
throw err;
|
|
}
|
|
|
|
// The data will contain a user and a token.
|
|
const { user, token } = data;
|
|
|
|
// Send the state back.
|
|
postMessage.post(HANDLE_SUCCESSFUL_LOGIN, { user, token });
|
|
|
|
// Close the window when all went well.
|
|
setTimeout(() => {
|
|
window.close();
|
|
}, 50);
|
|
});
|