|
37 | 37 | 'uiSelectConfig', |
38 | 38 | 'tooltipsConfProvider', |
39 | 39 | '$provide', |
| 40 | + 'RELAY_CONFIG', |
40 | 41 | function ( |
41 | 42 | $routeProvider, |
42 | 43 | $translateProvider, |
|
45 | 46 | jwtInterceptorProvider, |
46 | 47 | uiSelectConfig, |
47 | 48 | tooltipsConfProvider, |
48 | | - $provide) { |
| 49 | + $provide, |
| 50 | + RELAY_CONFIG) { |
49 | 51 |
|
50 | 52 | function makeStateful($delegate) { |
51 | 53 | $delegate.$stateful = true; |
|
139 | 141 | controllerAs: 'vm' |
140 | 142 | }) |
141 | 143 | .when('/signup/registration', { |
142 | | - templateUrl: 'partials/signup/registration.html', |
| 144 | + templateUrl: RELAY_CONFIG.useClerkAuthentication ? 'partials/signup/registration-w-password.html' : 'partials/signup/registration.html', |
143 | 145 | controller: 'RegistrationCtrl', |
144 | 146 | controllerAs: 'vm' |
145 | 147 | }) |
| 148 | + .when('/signup/otp-validation', { |
| 149 | + templateUrl: 'partials/signup/otp-validation.html', |
| 150 | + controller: 'OtpValidationCtrl', |
| 151 | + controllerAs: 'vm' |
| 152 | + }) |
146 | 153 | .when('/settings/my-plan', { |
147 | 154 | templateUrl: 'partials/settings/my-plan.html', |
148 | 155 | controller: 'PlanCtrl', |
|
182 | 189 | .preferredLanguage('en') |
183 | 190 | .useSanitizeValueStrategy('sanitizeParameters'); |
184 | 191 |
|
185 | | - jwtInterceptorProvider.tokenGetter = ['auth', function (auth) { return auth.getApiToken(); }]; |
| 192 | + jwtInterceptorProvider.tokenGetter = [ |
| 193 | + 'auth', '$q', |
| 194 | + function (auth, $q) { |
| 195 | + return $q.when(auth.getAuthToken()); |
| 196 | + } |
| 197 | + ]; |
186 | 198 |
|
187 | 199 | $httpProvider.interceptors.push('jwtInterceptor'); |
188 | 200 |
|
|
199 | 211 | 'jwtHelper', |
200 | 212 | '$locale', |
201 | 213 | 'utils', |
| 214 | + '$q', |
| 215 | + '$route', |
202 | 216 | function ( |
203 | 217 | $rootScope, |
204 | 218 | auth, |
|
207 | 221 | $translate, |
208 | 222 | jwtHelper, |
209 | 223 | $locale, |
210 | | - utils) { |
| 224 | + utils, |
| 225 | + $q, |
| 226 | + $route) { |
211 | 227 |
|
212 | 228 | function applyCultureFormats() { |
213 | 229 | var locale = getLocale($translate.use()); |
|
218 | 234 |
|
219 | 235 | $rootScope.$on('$translateChangeEnd', applyCultureFormats); |
220 | 236 |
|
221 | | - $rootScope.$on('$locationChangeStart', function () { |
| 237 | + var _authReadyResolved = false; |
| 238 | + auth.ready.finally(function () { _authReadyResolved = true; }); |
| 239 | + |
| 240 | + $rootScope.$on('$locationChangeStart', function (event, next, current) { |
| 241 | + var nextRelativeUrl = (next && next.split('#')[1]) || '/'; |
| 242 | + var forceLogoutUrls = [ |
| 243 | + '/login', |
| 244 | + '/signup/registration', |
| 245 | + '/signup/otp-validation', |
| 246 | + '/signup/succeed', |
| 247 | + '/signup/confirmation' |
| 248 | + ]; |
| 249 | + |
| 250 | + if (forceLogoutUrls.indexOf(nextRelativeUrl) !== -1) { |
| 251 | + auth.logOut(); |
| 252 | + } |
| 253 | + |
| 254 | + var unauthenticatedAllowed = [ |
| 255 | + '/login', |
| 256 | + '/signup/registration', |
| 257 | + '/signup/otp-validation', |
| 258 | + '/signup/confirmation', |
| 259 | + '/signup/error', |
| 260 | + '/signup/succeed', |
| 261 | + '/temporal-token-error', |
| 262 | + '/dkim-configuration-tutorial' |
| 263 | + ]; |
| 264 | + |
| 265 | + if (!_authReadyResolved && unauthenticatedAllowed.indexOf(nextRelativeUrl) === -1) { |
| 266 | + event.preventDefault(); |
| 267 | + auth.ready.finally(function () { |
| 268 | + if ($location.url() === nextRelativeUrl) { |
| 269 | + $route.reload(); |
| 270 | + } else { |
| 271 | + $location.url(nextRelativeUrl); |
| 272 | + } |
| 273 | + }); |
| 274 | + return; |
| 275 | + } |
| 276 | + |
222 | 277 | if ($window.ga) { |
223 | 278 | $window.ga('send', { |
224 | 279 | 'hitType': 'pageview', |
|
264 | 319 |
|
265 | 320 | function verifyAuthorization($location, auth) { |
266 | 321 | var openForAllUrls = ['/signup/error', '/temporal-token-error', '/dkim-configuration-tutorial']; |
267 | | - var requireLogoutUrls = ['/signup/confirmation', '/login', '/signup/registration', '/signup/succeed', '/loginAdmin']; |
| 322 | + var requireLogoutUrls = ['/signup/confirmation', '/login', '/signup/registration', '/signup/otp-validation', '/signup/succeed', '/loginAdmin']; |
268 | 323 | var requireTemporalAuthUrls = ['/reset-password', '/change-email']; |
269 | 324 |
|
270 | 325 | // TODO: optimize it |
|
0 commit comments