Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Fixed some bugs. iframe fully working
Browse files Browse the repository at this point in the history
  • Loading branch information
barankyle committed Mar 2, 2024
1 parent a8e78a2 commit 6561bc3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 78 deletions.
6 changes: 3 additions & 3 deletions packages/client-core/src/user/services/AuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
stateNamespaceKey,
syncStateWithLocalStorage
} from '@etherealengine/hyperflux'
import openPopup from "../../util/open-popup";

import {
AvatarID,
Expand Down Expand Up @@ -222,7 +221,7 @@ const getToken = async(): Promise<string> => {
const authState = getMutableState(AuthState)
const accessToken = authState?.authUser?.accessToken?.value
return Promise.resolve(accessToken?.length > 0 ? accessToken : null)
} //else window.location.href = `${clientUrl}/main-site-cookie-acknowledgment.html?redirect=${window.location}`
}
else {
iframe.style.display = 'block'
return await new Promise(resolve => {
Expand All @@ -239,11 +238,12 @@ const getToken = async(): Promise<string> => {
const hasAccessListener = async function(e) {
console.log('got message from iframe for hasAccessListener', e, e?.data)
window.removeEventListener('message', hasAccessListener)
if (!e.data) resolve({ hasStorageAccess: false, cookieSet: false })
if (!e.data) resolve('')
const data = JSON.parse(e.data)
console.log('data', data)
console.log('Waiting for token after click')
const token = await waitForToken(win, clientUrl)
iframe.style.display = 'none'
resolve(token)
}
window.addEventListener('message', hasAccessListener)
Expand Down
24 changes: 24 additions & 0 deletions packages/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@
})
})
}

//Base height and width of cross-origin iframe
const w = 300
const h = 400

const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;

let width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
let height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

const systemZoom = width / window.screen.availWidth;
const left = (width - w) / 2 / systemZoom + dualScreenLeft
const topSetting = (height - h) / 2 / systemZoom + dualScreenTop

document.addEventListener('DOMContentLoaded', async (event) => {
console.log('Setting root iframe style')
const rootIframe = document.getElementById('root-cookie-accessor')
console.log('rootIframe', rootIframe)
rootIframe.style.width = `${w / systemZoom}px`
rootIframe.style.height = `${h / systemZoom}px`
rootIframe.style.top = `${topSetting}px`
rootIframe.style.left = `${left}px`
})
</script>
</head>
<body>
Expand Down
70 changes: 0 additions & 70 deletions packages/client/public/main-site-cookie-acknowledgment.html

This file was deleted.

11 changes: 10 additions & 1 deletion packages/client/public/root-cookie-accessor-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,18 @@
console.log('Cookie accessor loaded')
document.getElementById('confirmButton').onclick = async event => {
console.log('confirmButton clicked')
document.cookie = 'visited=true; SameSite=None; Secure'
// document.cookie = 'visited=true; SameSite=None; Secure'
const requestStorageAccessResponse = await document.requestStorageAccess()
console.log('requestStorageAccessResponse', requestStorageAccessResponse)
if (requestStorageAccessResponse == null) {
console.log('storage access granted')

const cookieSet = document.cookie && document.cookie
.split("; ")
.find((row) => row.startsWith(`visited=`) || row.startsWith('allowedDomains='))
console.log('cookieset', cookieSet)
parent.postMessage(JSON.stringify({ hasStorageAccess: true, cookieSet }), origin)
}

//If there's a redirect URL, then upon completion, go back to the original URL
// if (isRedirect) {
Expand Down
8 changes: 4 additions & 4 deletions scripts/build_minikube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ fi

if [ -z "$VITE_APP_HOST" ]
then
VITE_APP_HOST=local.etherealengine.org
VITE_APP_HOST=meep.etherealengine.uk
else
VITE_APP_HOST=$VITE_APP_HOST
fi

if [ -z "$VITE_SERVER_HOST" ]
then
VITE_SERVER_HOST=api-local.etherealengine.org
VITE_SERVER_HOST=api-meep.etherealengine.uk
else
VITE_SERVER_HOST=$VITE_SERVER_HOST
fi
Expand All @@ -81,7 +81,7 @@ fi

if [ -z "$VITE_INSTANCESERVER_HOST" ]
then
VITE_INSTANCESERVER_HOST=instanceserver-local.etherealengine.org
VITE_INSTANCESERVER_HOST=instanceserver-meep.etherealengine.uk
else
VITE_INSTANCESERVER_HOST=$VITE_INSTANCESERVER_HOST
fi
Expand Down Expand Up @@ -128,7 +128,7 @@ else
VITE_FEATHERS_STORE_KEY=VITE_FEATHERS_STORE_KEY
fi


echo $VITE_APP_HOST

# ./generate-certs.sh

Expand Down

0 comments on commit 6561bc3

Please sign in to comment.