0

So, this is issue:

Uncaught InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

This happens when I trying to encode data when session starts, so in auth.js I have this:

function Auth($rootScope, $window, $state, Restangular, userInfo) {
  var token = $window.localStorage.token;
  if (token) {
    var payload = JSON.parse($window.atob(token.split('.')[1]));
    $rootScope.currentUser = payload.user;
  }

  return {
    signup: function(userinfo, callback) {
      var cb = callback || angular.noop;
      Restangular.all('auth/signup').post(userinfo).then(function() {
        return cb();
      }, function(response) {
        return cb(response.data);
      });
    },
    login: function(user, callback) {
      var cb = callback || angular.noop;
      Restangular.all('auth/login').post(user).then(function(data) {
        $window.localStorage.token = data.token;
        var payload = JSON.parse($window.atob(data.token.split('.')[1]));
        $rootScope.currentUser = payload.user;
        return cb();
      }, function(response) {
        delete $window.localStorage.token;
        return cb(response.data);
      });
    }

On other machines it works fine, but I have this problem. So, can you tell me from what can i start to find solution? This and this already saw. There is no idea in my head

Community
  • 1
  • 1
Merge-pony
  • 1,668
  • 3
  • 18
  • 32

1 Answers1

1

Think we're looking at the same Tut. Instead of:

$window.atob(data.token.split('.')[1])

Try this:

window.atob(window.localStorage['YOUR-ELEMENT'].split('.')[1])

"$window" is not defined.

Thomee
  • 59
  • 5