+
+
+
-
- + Runway Gen4 Web App +
+
@@ -139,14 +154,15 @@
-
-
-
diff --git a/public/js/script.js b/public/js/script.js
index cd54c7a..a9693f4 100644
--- a/public/js/script.js
+++ b/public/js/script.js
@@ -9,21 +9,8 @@ let selectedImageFile = null;
// Initialize MSAL or check for existing auth
async function initializeMSAL() {
try {
- // First, check if we have auth state from landing page
- const storedToken = localStorage.getItem('runway_access_token');
- const storedAuthState = localStorage.getItem('runway_auth_state');
-
- if (storedToken && storedAuthState) {
- const tokenData = JSON.parse(storedToken);
- const authState = JSON.parse(storedAuthState);
-
- // Check if token is still valid (not expired)
- if (Date.now() < tokenData.expires_at) {
- currentUser = tokenData.user;
- updateAuthUI();
- return; // Skip MSAL initialization if we have valid token
- }
- }
+ // Always start by showing the login screen
+ showLoginScreen();
// Initialize MSAL for this page
const configResponse = await fetch('backend/config_client.php');
@@ -62,16 +49,13 @@ async function initializeMSAL() {
// Clean up the URL (remove auth parameters)
window.history.replaceState({}, document.title, window.location.pathname);
- } else {
- // Check if user was already authenticated
- const accounts = msalInstance.getAllAccounts();
- if (accounts.length > 0) {
- currentUser = accounts[0];
- msalInstance.setActiveAccount(currentUser);
- }
+ // Show main app since user just authenticated
+ updateAuthUI();
+ return;
}
- updateAuthUI();
+ // Don't automatically log in - always show login screen first
+ currentUser = null;
} catch (error) {
console.error('MSAL initialization failed:', error);
showAuthError();
@@ -80,6 +64,9 @@ async function initializeMSAL() {
// Sign In function
async function signIn() {
+ // Show loading state immediately
+ showLoginLoading();
+
if (!msalInstance) {
// If MSAL not initialized, redirect to portal for authentication
window.location.href = 'http://localhost:3000/';
@@ -104,14 +91,21 @@ async function signIn() {
};
localStorage.setItem('runway_access_token', JSON.stringify(tokenData));
+ // Hide loading state and update UI
+ hideLoginLoading();
updateAuthUI();
} catch (error) {
console.error("Login failed:", error);
- showErrorMessage(generalErrorMessage, "Login failed: " + error.message);
+ hideLoginLoading();
+ // Could show error message on login screen if needed
+ const generalErrorMessage = document.getElementById('general-error-message');
+ if (generalErrorMessage) {
+ showErrorMessage(generalErrorMessage, "Login failed: " + error.message);
+ }
}
}
-// Sign Out function - redirect to portal
+// Sign Out function - return to login screen
async function signOut() {
// Clear any stored tokens
localStorage.removeItem('runway_access_token');
@@ -120,43 +114,72 @@ async function signOut() {
// Clear current user state
currentUser = null;
- // If MSAL is initialized, logout from Microsoft
+ // If MSAL is initialized, logout from Microsoft silently
if (msalInstance && msalInstance.getAllAccounts().length > 0) {
- await msalInstance.logoutRedirect({
- postLogoutRedirectUri: 'https://ai-sandbox.oliver.solutions/runway-video/'
- });
- } else {
- // If no MSAL session, just redirect
- window.location.href = 'https://ai-sandbox.oliver.solutions/runway-video/';
+ try {
+ await msalInstance.logoutSilent();
+ } catch (error) {
+ console.log('Silent logout failed, continuing with local logout');
+ }
}
- // Update UI immediately
+ // Update UI to show login screen
updateAuthUI();
}
+// Show Login Screen
+function showLoginScreen() {
+ const loginScreen = document.getElementById('login-screen-container');
+ const mainApp = document.getElementById('main-app-container');
+ const loginLoading = document.getElementById('login-loading');
+
+ if (loginScreen) loginScreen.classList.remove('hidden');
+ if (mainApp) mainApp.classList.add('hidden');
+ if (loginLoading) loginLoading.classList.add('hidden');
+}
+
+// Show Main App
+function showMainApp() {
+ const loginScreen = document.getElementById('login-screen-container');
+ const mainApp = document.getElementById('main-app-container');
+
+ if (loginScreen) loginScreen.classList.add('hidden');
+ if (mainApp) mainApp.classList.remove('hidden');
+}
+
+// Show Login Loading State
+function showLoginLoading() {
+ const loginLoading = document.getElementById('login-loading');
+ const loginBtn = document.getElementById('login-btn');
+
+ if (loginBtn) loginBtn.classList.add('hidden');
+ if (loginLoading) loginLoading.classList.remove('hidden');
+}
+
+// Hide Login Loading State
+function hideLoginLoading() {
+ const loginLoading = document.getElementById('login-loading');
+ const loginBtn = document.getElementById('login-btn');
+
+ if (loginLoading) loginLoading.classList.add('hidden');
+ if (loginBtn) loginBtn.classList.remove('hidden');
+}
+
// Update Authentication UI
function updateAuthUI() {
- const loginBtn = document.getElementById('login-btn');
- const logoutBtn = document.getElementById('logout-btn');
const userInfo = document.getElementById('user-info');
if (currentUser) {
- if (loginBtn) loginBtn.classList.add('hidden');
- if (logoutBtn) logoutBtn.classList.remove('hidden');
+ // User is authenticated - show main app
+ showMainApp();
if (userInfo) {
userInfo.textContent = `Welcome, ${currentUser.name || currentUser.username}`;
userInfo.classList.remove('text-red-600');
userInfo.classList.add('text-green-600');
}
} else {
- // Show sign in option without auto-redirect
- if (loginBtn) loginBtn.classList.remove('hidden');
- if (logoutBtn) logoutBtn.classList.add('hidden');
- if (userInfo) {
- userInfo.innerHTML = 'Please sign in to generate videos | ← Back to Portal';
- userInfo.classList.remove('text-green-600');
- userInfo.classList.add('text-red-600');
- }
+ // User is not authenticated - show login screen
+ showLoginScreen();
}
// Update generate button state only if the function exists
@@ -167,9 +190,9 @@ function updateAuthUI() {
// Show authentication error
function showAuthError() {
- const userInfo = document.getElementById('user-info');
- userInfo.innerHTML = 'Authentication initialization failed. ← Back to Portal';
- userInfo.classList.add('text-red-600');
+ // Show login screen with error state
+ showLoginScreen();
+ hideLoginLoading();
}
// Navigate back to portal
Generating your video...
-This may take a moment.
+ +
+
+
+
Generating your video...
+This may take a moment.
+