@@ -1648,14 +1648,18 @@ function onInitializeRegionalAuthClick() {
1648
1648
}
1649
1649
}
1650
1650
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
+
1651
1660
function onExchangeToken ( event ) {
1652
1661
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 ( ) ) {
1659
1663
return ;
1660
1664
}
1661
1665
@@ -1678,12 +1682,7 @@ function onExchangeToken(event) {
1678
1682
}
1679
1683
1680
1684
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 ( ) ) {
1687
1686
return ;
1688
1687
}
1689
1688
@@ -1696,12 +1695,7 @@ function onSetSuccessfulHandlerClick() {
1696
1695
}
1697
1696
1698
1697
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 ( ) ) {
1705
1699
return ;
1706
1700
}
1707
1701
@@ -1713,6 +1707,18 @@ function onSetFailureHandlerClick() {
1713
1707
) ;
1714
1708
}
1715
1709
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
+
1716
1722
/**
1717
1723
* Adds a new row to insert an OAuth custom parameter key/value pair.
1718
1724
* @param {!jQuery.Event } _event The jQuery event object.
@@ -2611,6 +2617,7 @@ function initApp() {
2611
2617
$ ( '#initialize-regional-auth-btn' ) . click ( onInitializeRegionalAuthClick ) ;
2612
2618
$ ( '#set-successful-handler-btn' ) . click ( onSetSuccessfulHandlerClick ) ;
2613
2619
$ ( '#set-failure-handler-btn' ) . click ( onSetFailureHandlerClick ) ;
2620
+ $ ( '#clear-regional-auth-id-btn' ) . click ( clearRegionalAuthInstance ) ;
2614
2621
}
2615
2622
2616
2623
$ ( initApp ) ;
0 commit comments