|
254 | 254 | }); |
255 | 255 |
|
256 | 256 | var _authReadyResolved = false; |
257 | | - auth.ready.finally(function () { _authReadyResolved = true; }); |
| 257 | + auth.ready.finally(function () { |
| 258 | + _authReadyResolved = true; |
| 259 | + if ($location.path() === '/login' && auth.isAuthed() && !auth.isTemporarilyAuthed()) { |
| 260 | + $location.path(auth.getDefaultUrl() || '/reports'); |
| 261 | + } |
| 262 | + }); |
258 | 263 |
|
259 | 264 | $rootScope.$on('$locationChangeStart', function (event, next, current) { |
260 | 265 | var nextRelativeUrl = (next && next.split('#')[1]) || '/'; |
261 | 266 | var forceLogoutUrls = [ |
262 | | - '/login', |
263 | 267 | '/signup/registration', |
264 | 268 | '/signup/otp-validation', |
265 | 269 | '/signup/succeed', |
|
340 | 344 |
|
341 | 345 | function verifyAuthorization($location, auth) { |
342 | 346 | var openForAllUrls = ['/signup/error', '/temporal-token-error', '/dkim-configuration-tutorial']; |
343 | | - var requireLogoutUrls = ['/signup/confirmation', '/login', '/signup/registration', '/signup/otp-validation', '/signup/succeed', '/loginAdmin']; |
| 347 | + var requireLogoutUrls = ['/signup/confirmation', '/signup/registration', '/signup/otp-validation', '/signup/succeed', '/loginAdmin']; |
| 348 | + var redirectIfAuthedUrls = ['/login']; |
344 | 349 | var requireTemporalAuthUrls = ['/reset-password', '/change-email']; |
345 | 350 |
|
346 | 351 | // TODO: optimize it |
|
349 | 354 | var userIsAuthedTemporarily = userIsAuthed && auth.isTemporarilyAuthed(); |
350 | 355 | var pageOpenForAll = openForAllUrls.includes(currentPath); |
351 | 356 | var pageRequireLogout = requireLogoutUrls.includes(currentPath); |
| 357 | + var pageRedirectIfAuthed = redirectIfAuthedUrls.includes(currentPath); |
352 | 358 | var pageRequireTemporalAuth = requireTemporalAuthUrls.includes(currentPath); |
353 | | - |
| 359 | + |
354 | 360 | if(!auth.isUrlAllowed(currentPath)) { |
355 | 361 | $location.path(auth.getDefaultUrl() || '/login'); |
356 | 362 | } |
|
366 | 372 | return; |
367 | 373 | } |
368 | 374 |
|
| 375 | + if (pageRedirectIfAuthed) { |
| 376 | + if (userIsAuthedTemporarily) { |
| 377 | + auth.logOut(); |
| 378 | + return; |
| 379 | + } |
| 380 | + if (userIsAuthed) { |
| 381 | + $location.path(auth.getDefaultUrl() || '/reports'); |
| 382 | + return; |
| 383 | + } |
| 384 | + return; |
| 385 | + } |
| 386 | + |
369 | 387 | if (pageRequireTemporalAuth && !userIsAuthedTemporarily) { |
370 | 388 | $location.path('/temporal-token-error'); |
371 | 389 | return; |
|
0 commit comments