Skip to content

Commit 7585b8a

Browse files
committed
review comments
1 parent 5fe9d5f commit 7585b8a

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

packages/auth/demo/src/index.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,14 +1648,18 @@ function onInitializeRegionalAuthClick() {
16481648
}
16491649
}
16501650

1651+
function clearRegionalAuthInstance() {
1652+
localStorage.removeItem('regionalAuthTenantId');
1653+
localStorage.removeItem('tokenRefreshHandlerType'); // Clear handler choice
1654+
$('#tenant-id-input').val('');
1655+
regionalAuth = null;
1656+
$('#regional-auth-status').text('regionalAuth is not initialized');
1657+
$('#token-handler-status').text('Token refresh handler is not set.');
1658+
}
1659+
16511660
function onExchangeToken(event) {
16521661
event.preventDefault();
1653-
if (!regionalAuth) {
1654-
onAuthError({
1655-
code: 'auth-not-initialized',
1656-
message:
1657-
'Regional Auth is not initialized. Please enter a Tenant ID and initialize.'
1658-
});
1662+
if (!validateRegionalAuth()) {
16591663
return;
16601664
}
16611665

@@ -1678,12 +1682,7 @@ function onExchangeToken(event) {
16781682
}
16791683

16801684
function onSetSuccessfulHandlerClick() {
1681-
if (!regionalAuth) {
1682-
onAuthError({
1683-
code: 'auth-not-initialized',
1684-
message:
1685-
'Regional Auth is not initialized. Please enter a Tenant ID and initialize.'
1686-
});
1685+
if (!validateRegionalAuth()) {
16871686
return;
16881687
}
16891688

@@ -1696,12 +1695,7 @@ function onSetSuccessfulHandlerClick() {
16961695
}
16971696

16981697
function onSetFailureHandlerClick() {
1699-
if (!regionalAuth) {
1700-
onAuthError({
1701-
code: 'auth-not-initialized',
1702-
message:
1703-
'Regional Auth is not initialized. Please enter a Tenant ID and initialize.'
1704-
});
1698+
if (!validateRegionalAuth()) {
17051699
return;
17061700
}
17071701

@@ -1713,6 +1707,18 @@ function onSetFailureHandlerClick() {
17131707
);
17141708
}
17151709

1710+
function validateRegionalAuth() {
1711+
if (!regionalAuth) {
1712+
onAuthError({
1713+
code: 'auth-not-initialized',
1714+
message:
1715+
'Regional Auth is not initialized. Please enter a Tenant ID and initialize.'
1716+
});
1717+
return false;
1718+
}
1719+
return true;
1720+
}
1721+
17161722
/**
17171723
* Adds a new row to insert an OAuth custom parameter key/value pair.
17181724
* @param {!jQuery.Event} _event The jQuery event object.
@@ -2611,6 +2617,7 @@ function initApp() {
26112617
$('#initialize-regional-auth-btn').click(onInitializeRegionalAuthClick);
26122618
$('#set-successful-handler-btn').click(onSetSuccessfulHandlerClick);
26132619
$('#set-failure-handler-btn').click(onSetFailureHandlerClick);
2620+
$('#clear-regional-auth-id-btn').click(clearRegionalAuthInstance);
26142621
}
26152622

26162623
$(initApp);

0 commit comments

Comments
 (0)