(function() { if (typeof jQuery === 'undefined') { console.warn('SSO async check: jQuery is not loaded'); return; } if (window._ssoCheckDone === true) { return; } window._ssoCheckDone = true; var serverAppUrl = 'https://nsso.ewha.ac.kr/sso'; var loginUrl = '/_custom/ewha/sso/login.jsp'; // 원래 접근하려던 페이지 URL (세션에서 가져온 값 또는 현재 페이지 URL) var originalUrlElement = document.getElementById('sso-original-url'); var originalUrl = originalUrlElement ? originalUrlElement.getAttribute('data-original-url') : null; var currentUrl = (originalUrl && originalUrl !== '' && originalUrl !== 'null') ? originalUrl : (window.location.pathname + window.location.search); // contextPath 제거 var contextPath = ''; if (contextPath && contextPath !== '' && currentUrl.startsWith(contextPath)) { currentUrl = currentUrl.substring(contextPath.length()); } // SSO 인증 상태 확인 (비동기) $.ajax({ url: serverAppUrl + '/api/ewha/auth/status', method: 'POST', dataType: 'json', xhrFields: { withCredentials: true }, timeout: 2000, error: function(xhr, status, error) { console.log('SSO async check: Not logged in or error occurred'); window._ssoCheckDone = false; }, success: function(response) { var result = response.result; if (result === true || result == true) { console.log('SSO async check: Logged in - redirecting to SSO login flow'); var finalLoginUrl = loginUrl + '?returnUrl=' + encodeURIComponent(currentUrl); window.location.href = finalLoginUrl; } else { console.log('SSO async check: Not logged in'); window._ssoCheckDone = false; } } }); })();