muzi jack muzi jack - 5 months ago 33
AngularJS Question

I've been following the Auth0 ionic app tutorial having challenges with the idToken it returns undefined

i'm getting this error- ReferenceError: idToken is not defined at controllers.js:99 at auth0-angular4.js:619. what could be the issue with my tokens?

.controller('loginCtrl', function($scope, $firebaseObject, $firebaseAuth, $state, $timeout, Auth, store, $location, auth, $rootScope, jwtHelper) {

$scope.login = function() {
auth.signin({
authParams: {
scope: 'openid offline-access',
device: 'Mobile device'
}

}, function(profile, token, accessToken, state, refreshToken) {
store.set('store', profile);
store.set('token', idToken);
store.set('refreshToken', refreshToken);
auth.getToken({
api: 'firebase'
}).then(function(delegate) {
store.set('firebaseToken', delegate.id_token);
$state.go('tabsController.pendingTasks');

}, function(error) {

})
})
$rootScope.$on('$locationChangeStart', function() {
if (!auth.isAuthenticated) {
var token = store.get('token');
if (token) {
if (!jwtHelper.isTokenExpired(token)) {
auth.authenticate(store.get('profile'), token);
} else {
// Use the refresh token we had
auth.refreshIdToken(refreshToken).then(function(idToken) {
store.set('token', idToken);
auth.authenticate(store.get('profile'), token);
});
}
}
}
});

}


})


this occurs after calling the login() function

Answer

You are calling

store.set('token', idToken);

on line 12 of your sample code, but the parameter being passed in to the function (on line 10) is named token.

So try changing line 12 to

store.set('token', token);

Comments