Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

"global is undefined" #209

Open
mzguimaraes opened this issue Oct 2, 2019 · 2 comments
Open

"global is undefined" #209

mzguimaraes opened this issue Oct 2, 2019 · 2 comments

Comments

@mzguimaraes
Copy link

Technologies used: Angular 8.1.3, Firefox 68.1.0esr

Importing this library using import { CognitoAuth } from 'amazon-cognito-auth-js/dist/amazon-cognito-auth'; to grab the prebuilt Webpack distribution, as recommended by issue #13 .

Cognito is set up to use a 3rd party federated ID provider internal to my company. We're using the code grant flow.

Some authentication step after returning with the grant code is calling a function named decode, I believe defined in DecodingHelper.js. That code calls global.atob(). which throws the following error at line 730 of the Webpacked file: ERROR TypeError: "global is undefined"

It appears to be preventing the library from writing the credentials to localStorage.

I was able to fix this issue by changing the definition of decode() in the Webpack file to

var decode = exports.decode = function decode(str) {
	// return global.atob(str);
	return global ? global.atob(str) : window.atob(str);
};
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))

but this is not an ideal way to fix this bug.

@wallacemv
Copy link

i have same problem with angular 8 :( pls help us

@wallacemv
Copy link

@mzguimaraes try this in your polyfills.ts
(window as any).global = window;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants