zavadil-ts-common 1.1.50 → 1.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -125,7 +125,7 @@ export class RestClientWithOAuth extends RestClient {
125
125
  }
126
126
 
127
127
  /**
128
- * Try to obtain access token, then return true or throw an Error.
128
+ * Try to obtain access token, then return true or reject.
129
129
  * This is basically only used when initializing and trying to determine whether we need to redirect user to login page
130
130
  */
131
131
  checkAccessToken(privilege?: string): Promise<boolean> {
@@ -134,4 +134,16 @@ export class RestClientWithOAuth extends RestClient {
134
134
  .then((accessToken) => true);
135
135
  }
136
136
 
137
+ checkAndRedirectToLogin(): Promise<boolean> {
138
+ return this.checkAccessToken()
139
+ .catch(
140
+ () => this.getServerInfo().then(
141
+ (si) => {
142
+ document.location = `${si.oauthServerUrl}/login?app_name=${si.targetAudience}&redirect_url=${document.location}`;
143
+ return Promise.resolve(false);
144
+ }
145
+ )
146
+ );
147
+ }
148
+
137
149
  }