test('should generate correct uri', () => { const uri = auth.uri(); const parsed = url.parse(uri); const params = qs.parse(parsed.query); expect(parsed.host).toEqual('abtwallet.io'); expect(parsed.pathname).toEqual('/i/'); expect(params.action).toEqual('requestAuth'); expect(decodeURIComponent(params.url).indexOf('zinc.abtnetwork.io')).toBeTruthy(); });
async function authorise(code: string) { const verifier = window.localStorage.getItem('auth.verifier'); const token = await getToken(code, verifier); if (token) { window.localStorage.setItem('auth.token', JSON.stringify(token)); setState({ type: authStates.authorized, token }); const link = { pathname: Router.asPath.split('?')[0], // TODO: This is very app specific, but it's an absolute pain to try and get this to work // The side effect is that it removes the rest of the URL params if there are any query: { action: Router.query.action, }, }; Router.replace(link, link, { shallow: true }); } else { const { verifier, loginUrl } = createLoginUrlWithVerifier(); window.localStorage.setItem('auth.verifier', verifier); setState(({ type: authStates.unauthorized, loginUrl }: Unauthorized)); // TODO: nicer solution than window.alert window.alert('Authorisation failed. Please try to log in again.'); } }