amazon-cognito-auth-js icon indicating copy to clipboard operation
amazon-cognito-auth-js copied to clipboard

"global is undefined"

Open mzguimaraes opened this issue 6 years ago • 2 comments

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.

mzguimaraes avatar Oct 02 '19 16:10 mzguimaraes

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

wallacemv avatar Feb 13 '20 14:02 wallacemv

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

wallacemv avatar Feb 14 '20 17:02 wallacemv