Skip to content

Commit 0f9e1a8

Browse files
committed
Handle error of un-authenticated user
1 parent 10891e5 commit 0f9e1a8

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Xrm.Portal.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ Xrm.Portal = {
1212
/*authorize: function() {
1313
},*/
1414
decode: function (token) {
15-
var base64Url = token.split('.')[1];
16-
var base64 = decodeURIComponent(atob(base64Url).split('').map(function (c) {
17-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
18-
}).join(''));
19-
20-
return JSON.parse(base64);
15+
if (token !== "") {
16+
var base64Url = token.split('.')[1];
17+
var base64 = decodeURIComponent(atob(base64Url).split('').map(function (c) {
18+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
19+
}).join(''));
20+
21+
return JSON.parse(base64);
22+
}
23+
throw "No login user is detected.";
2124
},
2225
get: function () {
2326
return $.get("/_services/auth/token");

0 commit comments

Comments
 (0)