@@ -1714,7 +1714,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1714
1714
return this . urlHelper . parseQueryString ( queryString ) ;
1715
1715
}
1716
1716
1717
- public tryLoginCodeFlow ( options : LoginOptions = null ) : Promise < void > {
1717
+ public async tryLoginCodeFlow ( options : LoginOptions = null ) : Promise < void > {
1718
1718
options = options || { } ;
1719
1719
1720
1720
const querySource = options . customHashFragment
@@ -1761,6 +1761,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1761
1761
1762
1762
if ( ! options . disableNonceCheck ) {
1763
1763
if ( ! nonceInState ) {
1764
+ this . saveRequestedRoute ( ) ;
1764
1765
return Promise . resolve ( ) ;
1765
1766
}
1766
1767
@@ -1776,11 +1777,31 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1776
1777
this . storeSessionState ( sessionState ) ;
1777
1778
1778
1779
if ( code ) {
1779
- return this . getTokenFromCode ( code , options ) . then ( ( _ ) => null ) ;
1780
+ await this . getTokenFromCode ( code , options ) ;
1781
+ this . restoreRequestedRoute ( ) ;
1782
+ return Promise . resolve ( ) ;
1780
1783
} else {
1781
1784
return Promise . resolve ( ) ;
1782
1785
}
1783
1786
}
1787
+
1788
+ return Promise . reject ( ) ;
1789
+ }
1790
+
1791
+ private saveRequestedRoute ( ) {
1792
+ if ( this . config . preserveRequestedRoute ) {
1793
+ this . _storage . setItem (
1794
+ 'requested_route' ,
1795
+ window . location . pathname + window . location . search
1796
+ ) ;
1797
+ }
1798
+ }
1799
+
1800
+ private restoreRequestedRoute ( ) {
1801
+ const requestedRoute = this . _storage . getItem ( 'requested_route' ) ;
1802
+ if ( requestedRoute ) {
1803
+ history . replaceState ( null , '' , window . location . origin + requestedRoute ) ;
1804
+ }
1784
1805
}
1785
1806
1786
1807
/**
0 commit comments