diff --git a/README.md b/README.md index fe17397..de33908 100644 Binary files a/README.md and b/README.md differ diff --git a/client/public/auth.mjs b/client/public/auth.mjs index d7977c4..a81f562 100644 --- a/client/public/auth.mjs +++ b/client/public/auth.mjs @@ -7,11 +7,13 @@ const AUTH0CONFIG = { }; let auth0 = null; +let ready = false; async function CheckRedirect() { const isAuthenticated = await auth0.isAuthenticated(); if (isAuthenticated) { localStorage.setItem('loggedIn', true); + ready = true; return; } @@ -23,6 +25,7 @@ async function CheckRedirect() { } catch (e) { window.alert(e.message || 'authentication error, sorry'); localStorage.setItem('loggedIn', false); + ready = false; Signout(); } @@ -32,9 +35,7 @@ async function CheckRedirect() { } export async function InitAuth0() { - // localStorage.setItem('loggedIn', false); - // localStorage.setItem('user', 'Guest'); - // localStorage.setItem('admin', false); + ready = false; auth0 = await window.createAuth0Client({ domain: AUTH0CONFIG.domain, @@ -50,6 +51,7 @@ export async function InitAuth0() { localStorage.setItem('user', user.given_name || user.nickname); NotifyNavbar('login', user); localStorage.setItem('loggedIn', true); + ready = true; // tell the server about the logon, so that it can make the proper // entry in the database, if there is for example an address @@ -69,6 +71,11 @@ export async function InitAuth0() { } export async function GetToken() { + /* eslint-disable-next-line */ + while (!ready) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + const token = await auth0.getTokenSilently(); return token; } @@ -90,6 +97,7 @@ export async function LoginSignup() { export async function Signout() { localStorage.setItem('loggedIn', false); + ready = false; localStorage.setItem('user', 'Guest'); localStorage.setItem('admin', false); await auth0.logout({ diff --git a/client/public/basket/index.html b/client/public/basket/index.html index c46bece..11018d9 100644 --- a/client/public/basket/index.html +++ b/client/public/basket/index.html @@ -20,7 +20,7 @@ - + diff --git a/client/public/checkout/index.html b/client/public/checkout/index.html index fa6c7ac..b61df1d 100644 --- a/client/public/checkout/index.html +++ b/client/public/checkout/index.html @@ -19,7 +19,7 @@ - + diff --git a/client/public/components/basket-popout.mjs b/client/public/components/basket-popout.mjs index c17c69b..762d5af 100644 --- a/client/public/components/basket-popout.mjs +++ b/client/public/components/basket-popout.mjs @@ -66,7 +66,7 @@ class BasketPopout extends Component { {this.state.total} Items