-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GH-1092] Redirect the user to correct URL after login #1094
Changes from 2 commits
6bbe404
26fc0af
8de0066
cdfe85b
27d311f
5f177e9
288e5e9
2b398d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { useState } from 'react'; | |
import { Navigate, useLocation } from 'react-router-dom'; | ||
import { Login } from '../views/Login'; | ||
import { useAuth } from '../hooks'; | ||
import { regexToValidateWindowPathName } from '../../utils'; | ||
|
||
export const AuthGuard = (props) => { | ||
const { children } = props; | ||
|
@@ -15,6 +16,13 @@ export const AuthGuard = (props) => { | |
setRequestedLocation(location.pathname); | ||
} | ||
|
||
if ( | ||
!sessionStorage.getItem('window-location') && | ||
location.pathname !== '/' | ||
) { | ||
sessionStorage.setItem('window-location', location.pathname); | ||
} | ||
|
||
return <Login />; | ||
} | ||
|
||
|
@@ -23,6 +31,22 @@ export const AuthGuard = (props) => { | |
return <Navigate to={requestedLocation} />; | ||
} | ||
|
||
if ( | ||
sessionStorage.getItem('window-location') && | ||
SofiaSazonova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
location.pathname !== sessionStorage.getItem('window-location') | ||
) { | ||
const windowPathLocation = sessionStorage.getItem('window-location'); | ||
sessionStorage.removeItem('window-location'); | ||
// Check if the window-location only contains alphanumeric and / in it and its not tampered | ||
if (!regexToValidateWindowPathName.test(windowPathLocation)) | ||
return <>{children}</>; | ||
// A guardrail to limit the string of the pathname to a certain characters | ||
if (windowPathLocation.length > 50) return <>{children}</>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's wrong with long URLs? Why 50? Maybe it's better to make it a param, not magic constant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @SofiaSazonova , Thanks for the review. I added this number by heuristically checking the length of the windowpath for the longest URL. I think it was the URL to table in a dataset and it was approx 33 - 37 characters. I can make it a param and store it in the contants.js . What are your thoughts ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather make it a setting, rather then a constant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @SofiaSazonova , Thanks for re-reviewing it. In the length check we are actually checking the windowPath length . The window path length is excluding the URL domain. Thus, the window path length will contain all the resource paths to the data.all related items ( datasets, shares, tables, etc ) and won't contain anything else that might be customer specific. Unless a customer integrates a custom module ( not on data.all O.S. ) by themselves which have very large windowpath names I don't think we need to make it configurable. Please let me know if you want to still make it configurable. @dlpzx , would also like to know your thoughts on this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TejasRGitHub in this case, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @SofiaSazonova , Updated code to make it a constant . Please let me know if it looks good |
||
return <Navigate to={windowPathLocation} replace={true} />; | ||
} else { | ||
sessionStorage.removeItem('window-location'); | ||
} | ||
|
||
return <>{children}</>; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking this explicitly so that we do not set the '/' which will happen in case a user logsout and then pastes the URL in the browser and again tries to logback with the new URL . As the user logged out the redirect URL is the base URL and then this gets stored in the window-location which should not be the case. We only want to store window location path pointing to specific path