Skip to content

Commit

Permalink
Merge pull request #1118 from EscolaLMS/bugfix/WELLMS-554
Browse files Browse the repository at this point in the history
redirect admin proper path
  • Loading branch information
victazzz authored Jan 24, 2025
2 parents b9b3473 + b7e0340 commit c6629ae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
1 change: 1 addition & 0 deletions src/pages/Scorm/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const H5PPreviewPage: React.FC = () => {
<Row>
<Col span={24}>
<Divider />

{uuid && <ScormPreview uuid={uuid} />}
</Col>
</Row>
Expand Down
1 change: 1 addition & 0 deletions src/pages/User/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const Login: React.FC = () => {
handleForgot({ ...values, return_url: `${window.location.origin}/#/user/reset-password` });
}
};

return (
<AuthLayout>
<ProForm
Expand Down

0 comments on commit c6629ae

Please sign in to comment.