diff --git a/src/app.tsx b/src/app.tsx
index 6ddfa15db..55986c076 100644
--- a/src/app.tsx
+++ b/src/app.tsx
@@ -41,20 +41,47 @@ export async function getInitialState(): Promise<{
}> {
refreshTokenCallback();
const fetchUserInfo = async () => {
+ // Combine the current pathname and search parameters into a full URL
+ const url = history.location.pathname + history.location.search;
+
try {
+ // Attempt to fetch the current user's data
const currentUser = await queryCurrentUser();
+
+ // If the user query is successful, return the user data
if (currentUser.success) {
return currentUser.data;
}
+
+ // If the user query fails (not successful), return undefined
return undefined;
} catch (error) {
+ // Check if the current path is in the list of authenticated paths
if (authpaths.includes(history.location.pathname)) {
- history.push(`/user/login`);
+ // If the URL does not already include a redirect parameter
+ if (!url.includes('redirect')) {
+ // Redirect the user to the login page
+ history.push(`/user/login`);
+
+ // If there is a "redirect" key in local storage, remove it
+ if (localStorage.getItem('redirect')) {
+ localStorage.removeItem('redirect');
+ }
+ }
} else {
- const url = history.location.pathname + history.location.search;
+ // If the path is not in the authenticated paths, redirect the user to the login page
+ // Include the current URL as the "redirect" query parameter to return after login
history.push(`/user/login?redirect=${url}`);
}
+ } finally {
+ // If the URL includes a "redirect" parameter and it is not already in local storage
+ if (url.includes('redirect') && !localStorage.getItem('redirect')) {
+ // Save the "redirect" value to local storage for future use
+ localStorage.setItem('redirect', url.split('redirect=')[1]);
+ }
}
+
+ // Return undefined if no user data is fetched or an error occurs
return undefined;
};
diff --git a/src/pages/Scorm/preview.tsx b/src/pages/Scorm/preview.tsx
index f133f891a..f8eaf5338 100644
--- a/src/pages/Scorm/preview.tsx
+++ b/src/pages/Scorm/preview.tsx
@@ -38,6 +38,7 @@ const H5PPreviewPage: React.FC = () => {
+
{uuid && }
diff --git a/src/pages/User/login/index.tsx b/src/pages/User/login/index.tsx
index ad606b272..ce620dc26 100644
--- a/src/pages/User/login/index.tsx
+++ b/src/pages/User/login/index.tsx
@@ -126,6 +126,7 @@ const Login: React.FC = () => {
handleForgot({ ...values, return_url: `${window.location.origin}/#/user/reset-password` });
}
};
+
return (